Re: [algogeeks] Re: adobe written round que

2012-01-18 Thread Arun Vishwanathan
@all : doesnt sudhir's solution seem to work?? @sudhir: can u explain yr logic? On Wed, Sep 21, 2011 at 8:31 AM, annarao kataru kataruanna...@gmail.comwrote: can u explain the logic behind this thanks in advance -- You received this message because you are subscribed to the Google

Re: [algogeeks] Re: adobe written round que

2011-09-21 Thread annarao kataru
can u explain the logic behind this thanks in advance -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: adobe written round que

2011-09-17 Thread priyanka raju
* * *#include fstream #include iostream using namespace std; bool flag=false; void check(int i) { int sum=0; char n[5]; itoa(i,n,10); for(int j=0;j5 n[j] != '\0';j++) { char p = n[j]; sum += atoi(p); } if(sum==3 || sum==6 || sum==9) flag = true; else if(sum9) check(sum); } void main() { int i;

Re: [algogeeks] Re: adobe written round que

2011-08-01 Thread Puneet Gautam
@ankit: not the last digit..!! it will be (last digit -3) or (last digit -3-3) whichever is positive.. :) On 7/31/11, Ankit Minglani ankit.mingl...@gmail.com wrote: yeah if it was a divisibility test then the question would have been too trivial .. the last digit after doing itoa will be the

Re: [algogeeks] Re: adobe written round que

2011-08-01 Thread shubham
Hi, we can show that (x/3) = (x/2) - (x/4) + (x/8) - (x/16) + infinity Proof: let s1 = (x/2)+(x/8)+(x/32)+...infinity = (x/2)/(1-(1/4)) [Geometric Progression , common Ratio(r) = 1/4] s2 = (x/4)+(x/16)+(x/64)+...infinity = (x/4)/(1-(1/4)) [Geometric Progression , common Ratio(r) =

Re: [algogeeks] Re: adobe written round que

2011-07-31 Thread Ankit Minglani
yeah if it was a divisibility test then the question would have been too trivial .. the last digit after doing itoa will be the remainder . On Sat, Jul 30, 2011 at 11:52 AM, nivedita arora vivaciousnived...@gmail.com wrote: i think solution of ankit is right ! sorry even i forgot tht que ws

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread SAMM
Single bit shift... int divide(int n) { n-=1; n=1; return n; } On 7/30/11, tech rascal techrascal...@gmail.com wrote: hw will u get the ans on repeated subtraction from the sum of the digits?? I mean if I hv 2 divide 27 by 3 thn first I'll find sum of the digits i.e, 2+7=9 then I'll

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread aditi garg
@Samm : Im not able to understand ur logic...im not getting the correct ans...can u explain the working taking n as 7? On Sat, Jul 30, 2011 at 12:25 PM, SAMM somnath.nit...@gmail.com wrote: Single bit shift... int divide(int n) { n-=1; n=1; return n; } On 7/30/11, tech rascal

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Ankit Minglani
#includestdio.h #includestdlib.h #includeconio.h #includestring.h #includemath.h int multiply(int a,int b) { int i; int temp=a; printf(\na=%d b=%d\n,a,b); for(i=1;ib;i++) a+=temp; printf(\nfinal a = %d,a); return(a); } void main () { int x,rem,quo=0,i,j;

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Puneet Gautam
I think the whole point and advantage of using itoa is to make the code suitable for larger integer inputs.. eg: if i/p is: 32765 , itoa gives 32765, we take each sum=3+2+7+6+5= 23 and then use repeated subtraction... Repeated subtraction on 2 digit no. is much faster than on 5 digit one..!!

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Abhishek Gupta
let the number be num so code is this int ans=0; while(num=3) { num=num-3; ans++; } No need to use itoa. This is simple division algo based on subtraction. On Sat, Jul 30, 2011 at 2:09 PM, Ankit Minglani ankit.mingl...@gmail.comwrote: #includestdio.h #includestdlib.h

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Roopam Poddar
The objective is to divide the number by 3 and not just check for it's divisibility. Adding the digits using itoa() and then repeated subtraction will check for it's divisibility by 3 and not give us the quotient. To get that you will have to carry out repeated subtraction on the number anyway.

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Ankur Khurana
@roopam : i got the question all wrong. . . On Sat, Jul 30, 2011 at 10:01 PM, Roopam Poddar mailroo...@gmail.comwrote: The objective is to divide the number by 3 and not just check for it's divisibility. Adding the digits using itoa() and then repeated subtraction will check for it's

Re: [algogeeks] Re: adobe written round que

2011-07-30 Thread Puneet Gautam
@roopam: Thats what i am saying... the function itoa only gives you the remainder, it doesnt provide quotient..we need to do repeated subtraction for that... On 7/30/11, Ankur Khurana ankur.kkhur...@gmail.com wrote: @roopam : i got the question all wrong. . . On Sat, Jul 30, 2011 at 10:01

[algogeeks] Re: adobe written round que

2011-07-30 Thread nivedita arora
i think solution of ankit is right ! sorry even i forgot tht que ws not divisibility test ..but to get quotient :-| On Jul 30, 10:03 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: @roopam : i got the question all wrong. . . On Sat, Jul 30, 2011 at 10:01 PM, Roopam Poddar

[algogeeks] Re: adobe written round que

2011-07-29 Thread nivedita arora
hmm ok got it . ..i can take gt sum of digits without having the number as string as well . i din exactly gt the whole point of using strings. they shud hv mentioned it explicitly i guess . . though thanks ankur On Jul 30, 1:15 am, Ankur Khurana ankur.kkhur...@gmail.com wrote: you shouldn't be

[algogeeks] Re: adobe written round que

2011-07-29 Thread Amit
well,well,well... a=x1; b=x2; c=(a+b)1; d=x3; x=c+d; actually i used the fact- 1/3 = 3/9 = ((1/2)+(1/4))/2 + 1/8 On Jul 30, 1:37 am, nivedita arora vivaciousnived...@gmail.com wrote: hmm ok got it . ..i can take gt sum of digits without having the number as string as well . i din exactly gt

Re: [algogeeks] Re: adobe written round que

2011-07-29 Thread aditi garg
ur expression forms 4/8=1/2 and not 1/3... On Sat, Jul 30, 2011 at 3:18 AM, Amit amitbaranwa...@gmail.com wrote: well,well,well... a=x1; b=x2; c=(a+b)1; d=x3; x=c+d; actually i used the fact- 1/3 = 3/9 = ((1/2)+(1/4))/2 + 1/8 On Jul 30, 1:37 am, nivedita arora

Re: [algogeeks] Re: adobe written round que

2011-07-29 Thread Sudhir mishra
int divideby3 (int num) { int sum = 0; while (num 3) { sum += num 2; num = (num 2) + (num 3); } if (num == 3) ++sum; return sum; } Thanks Regards...* รυ∂んเя мเรんяค* -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Re: adobe written round que

2011-07-29 Thread brijesh
@ankur I didnt get this... could u or anyone please elaborate! On Jul 30, 12:43 am, Ankur Khurana ankur.kkhur...@gmail.com wrote: when you use itoa , what you get is a string. get the sum of all the digits , using c-'0' and then use repeated subtraction . . . On Sat, Jul 30, 2011 at 1:01 AM,

Re: [algogeeks] Re: adobe written round que

2011-07-29 Thread ananth sharma
shift the number to left two times and subtract once... I.e. Int x=num; x=x2; x-=num; On 7/30/11, brijesh brijeshupadhyay...@gmail.com wrote: @ankur I didnt get this... could u or anyone please elaborate! On Jul 30, 12:43 am, Ankur Khurana ankur.kkhur...@gmail.com wrote: when you use itoa ,

[algogeeks] Re: adobe written round que

2011-07-29 Thread nivedita arora
@brijesh- itoa basically converts integer to string ..we are using the fact tht a number is multiple of 3 if its sum is multiple of 3 . we have int as string and we can traverse it ..for each character apply int sum+=*c-'0' (ankur missed the star :P) then on sum we use repeated subtraction...i

Re: [algogeeks] Re: adobe written round que

2011-07-29 Thread tech rascal
hw will u get the ans on repeated subtraction from the sum of the digits?? I mean if I hv 2 divide 27 by 3 thn first I'll find sum of the digits i.e, 2+7=9 then I'll apply repeated subtraction on 9, so hw will i reach to the ans?? On Sat, Jul 30, 2011 at 10:05 AM, nivedita arora