Re: [algogeeks] Re: Google written test

2012-03-21 Thread atul anand
@Hemesh : dats would be an over kill , you are converting O(n) solution to
a subset sum problem which NP

On Tue, Mar 20, 2012 at 7:35 PM, Hemesh Singh hemesh.mn...@gmail.comwrote:

 Isn't it a standard subset sum problem? You can generate the Fibonacci
 numbers and put them in an array. Now just apply the standard algorithm to
 find that which Fibonacci numbers add up to make the given sum. Please
 correct me if I am wrong.


 On Mon, Mar 19, 2012 at 8:58 PM, atul anand atul.87fri...@gmail.comwrote:

 @Gene : yeah i skipped ur updated code...its dere

 @shady : it is similar to fib encoding...you just need to reverse the
 output from gene code and append '1' at the end...
 while decoding it ...this extra '1' is not considered..
 i am nt sure but maybe the reason for adding '1' at the end is to mark
 end of word
 On 19 Mar 2012 19:10, shady sinv...@gmail.com wrote:

 @gene it does show your updated code.

 @atul from the given input it seems different from Fibonacci encoding.

 On Mon, Mar 19, 2012 at 5:32 PM, Gene gene.ress...@gmail.com wrote:

 Thanks.

 I noticed this too.  If the n'th 1/0 digit is supposed to correspond
 with the n'th fibonacci number, then my original code would have been
 right.  But the example isn't done this way.

 I  fixed the code to match the example the evening of the 18th
 (Eastern time), but I guess the change is not showing on your server
 yet.


 On Mar 19, 3:16 am, atul anand atul.87fri...@gmail.com wrote:
  @Gene :  your code will work fine by changing the argument passed from
  main(), you just need to call rite  f(n, 1, 1); from main instead of
  f(n,
  1, 0);
 
  On Mon, Mar 19, 2012 at 10:10 AM, atul anand atul.87fri...@gmail.com
 wrote:
 
 
 
 
 
 
 
   @all : i guess question is on Fibonacci coding.
 
   here you can find the algo :-
 
  http://en.wikipedia.org/wiki/Fibonacci_coding
 
   On Sun, Mar 18, 2012 at 2:58 AM, Atul Singh 
 atulsingh7...@gmail.comwrote:
 
   @Ravi...  there should be only one answer as for fibonacci
 representation
   of a number we have to include the part of the fibonacci number
 just less
   than the number then remaining part of the sum is filled by
 fibonacci
   numbers starting from 1
 
   suppose we have to convert 6 into fibonacci representation
   then 6 has two sum sets as {1,2,3} or {1,5}
 
   then the fibonacci number just less than 6 is 5 so bit
 representing 5 is
   set then for completing the sum to 6 bit 1 is also set.
   so *fibonacci representation of 6 is 1001 .* not 0111
 
   ATul Singh | Final Year  | Computer Science  Engineering | NIT
   Jalandhar  | 9530739855 |
 
--
   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
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Hemesh singh

  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Google written test

2012-03-20 Thread Hemesh Singh
Isn't it a standard subset sum problem? You can generate the Fibonacci
numbers and put them in an array. Now just apply the standard algorithm to
find that which Fibonacci numbers add up to make the given sum. Please
correct me if I am wrong.

On Mon, Mar 19, 2012 at 8:58 PM, atul anand atul.87fri...@gmail.com wrote:

 @Gene : yeah i skipped ur updated code...its dere

 @shady : it is similar to fib encoding...you just need to reverse the
 output from gene code and append '1' at the end...
 while decoding it ...this extra '1' is not considered..
 i am nt sure but maybe the reason for adding '1' at the end is to mark end
 of word
 On 19 Mar 2012 19:10, shady sinv...@gmail.com wrote:

 @gene it does show your updated code.

 @atul from the given input it seems different from Fibonacci encoding.

 On Mon, Mar 19, 2012 at 5:32 PM, Gene gene.ress...@gmail.com wrote:

 Thanks.

 I noticed this too.  If the n'th 1/0 digit is supposed to correspond
 with the n'th fibonacci number, then my original code would have been
 right.  But the example isn't done this way.

 I  fixed the code to match the example the evening of the 18th
 (Eastern time), but I guess the change is not showing on your server
 yet.


 On Mar 19, 3:16 am, atul anand atul.87fri...@gmail.com wrote:
  @Gene :  your code will work fine by changing the argument passed from
  main(), you just need to call rite  f(n, 1, 1); from main instead of
  f(n,
  1, 0);
 
  On Mon, Mar 19, 2012 at 10:10 AM, atul anand atul.87fri...@gmail.com
 wrote:
 
 
 
 
 
 
 
   @all : i guess question is on Fibonacci coding.
 
   here you can find the algo :-
 
  http://en.wikipedia.org/wiki/Fibonacci_coding
 
   On Sun, Mar 18, 2012 at 2:58 AM, Atul Singh atulsingh7...@gmail.com
 wrote:
 
   @Ravi...  there should be only one answer as for fibonacci
 representation
   of a number we have to include the part of the fibonacci number
 just less
   than the number then remaining part of the sum is filled by
 fibonacci
   numbers starting from 1
 
   suppose we have to convert 6 into fibonacci representation
   then 6 has two sum sets as {1,2,3} or {1,5}
 
   then the fibonacci number just less than 6 is 5 so bit representing
 5 is
   set then for completing the sum to 6 bit 1 is also set.
   so *fibonacci representation of 6 is 1001 .* not 0111
 
   ATul Singh | Final Year  | Computer Science  Engineering | NIT
   Jalandhar  | 9530739855 |
 
--
   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
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Hemesh singh

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Google written test

2012-03-19 Thread Gene
Thanks.

I noticed this too.  If the n'th 1/0 digit is supposed to correspond
with the n'th fibonacci number, then my original code would have been
right.  But the example isn't done this way.

I  fixed the code to match the example the evening of the 18th
(Eastern time), but I guess the change is not showing on your server
yet.


On Mar 19, 3:16 am, atul anand atul.87fri...@gmail.com wrote:
 @Gene :  your code will work fine by changing the argument passed from
 main(), you just need to call rite  f(n, 1, 1); from main instead of  f(n,
 1, 0);

 On Mon, Mar 19, 2012 at 10:10 AM, atul anand atul.87fri...@gmail.comwrote:







  @all : i guess question is on Fibonacci coding.

  here you can find the algo :-

 http://en.wikipedia.org/wiki/Fibonacci_coding

  On Sun, Mar 18, 2012 at 2:58 AM, Atul Singh atulsingh7...@gmail.comwrote:

  @Ravi...  there should be only one answer as for fibonacci representation
  of a number we have to include the part of the fibonacci number just less
  than the number then remaining part of the sum is filled by fibonacci
  numbers starting from 1

  suppose we have to convert 6 into fibonacci representation
  then 6 has two sum sets as {1,2,3} or {1,5}

  then the fibonacci number just less than 6 is 5 so bit representing 5 is
  set then for completing the sum to 6 bit 1 is also set.
  so *fibonacci representation of 6 is 1001 .* not 0111

  ATul Singh | Final Year  | Computer Science  Engineering | NIT
  Jalandhar  | 9530739855 |

   --
  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
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Google written test

2012-03-19 Thread shady
@gene it does show your updated code.

@atul from the given input it seems different from Fibonacci encoding.

On Mon, Mar 19, 2012 at 5:32 PM, Gene gene.ress...@gmail.com wrote:

 Thanks.

 I noticed this too.  If the n'th 1/0 digit is supposed to correspond
 with the n'th fibonacci number, then my original code would have been
 right.  But the example isn't done this way.

 I  fixed the code to match the example the evening of the 18th
 (Eastern time), but I guess the change is not showing on your server
 yet.


 On Mar 19, 3:16 am, atul anand atul.87fri...@gmail.com wrote:
  @Gene :  your code will work fine by changing the argument passed from
  main(), you just need to call rite  f(n, 1, 1); from main instead of
  f(n,
  1, 0);
 
  On Mon, Mar 19, 2012 at 10:10 AM, atul anand atul.87fri...@gmail.com
 wrote:
 
 
 
 
 
 
 
   @all : i guess question is on Fibonacci coding.
 
   here you can find the algo :-
 
  http://en.wikipedia.org/wiki/Fibonacci_coding
 
   On Sun, Mar 18, 2012 at 2:58 AM, Atul Singh atulsingh7...@gmail.com
 wrote:
 
   @Ravi...  there should be only one answer as for fibonacci
 representation
   of a number we have to include the part of the fibonacci number just
 less
   than the number then remaining part of the sum is filled by fibonacci
   numbers starting from 1
 
   suppose we have to convert 6 into fibonacci representation
   then 6 has two sum sets as {1,2,3} or {1,5}
 
   then the fibonacci number just less than 6 is 5 so bit representing 5
 is
   set then for completing the sum to 6 bit 1 is also set.
   so *fibonacci representation of 6 is 1001 .* not 0111
 
   ATul Singh | Final Year  | Computer Science  Engineering | NIT
   Jalandhar  | 9530739855 |
 
--
   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
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Google written test

2012-03-19 Thread atul anand
@Gene : yeah i skipped ur updated code...its dere

@shady : it is similar to fib encoding...you just need to reverse the
output from gene code and append '1' at the end...
while decoding it ...this extra '1' is not considered..
i am nt sure but maybe the reason for adding '1' at the end is to mark end
of word
On 19 Mar 2012 19:10, shady sinv...@gmail.com wrote:

 @gene it does show your updated code.

 @atul from the given input it seems different from Fibonacci encoding.

 On Mon, Mar 19, 2012 at 5:32 PM, Gene gene.ress...@gmail.com wrote:

 Thanks.

 I noticed this too.  If the n'th 1/0 digit is supposed to correspond
 with the n'th fibonacci number, then my original code would have been
 right.  But the example isn't done this way.

 I  fixed the code to match the example the evening of the 18th
 (Eastern time), but I guess the change is not showing on your server
 yet.


 On Mar 19, 3:16 am, atul anand atul.87fri...@gmail.com wrote:
  @Gene :  your code will work fine by changing the argument passed from
  main(), you just need to call rite  f(n, 1, 1); from main instead of
  f(n,
  1, 0);
 
  On Mon, Mar 19, 2012 at 10:10 AM, atul anand atul.87fri...@gmail.com
 wrote:
 
 
 
 
 
 
 
   @all : i guess question is on Fibonacci coding.
 
   here you can find the algo :-
 
  http://en.wikipedia.org/wiki/Fibonacci_coding
 
   On Sun, Mar 18, 2012 at 2:58 AM, Atul Singh atulsingh7...@gmail.com
 wrote:
 
   @Ravi...  there should be only one answer as for fibonacci
 representation
   of a number we have to include the part of the fibonacci number just
 less
   than the number then remaining part of the sum is filled by fibonacci
   numbers starting from 1
 
   suppose we have to convert 6 into fibonacci representation
   then 6 has two sum sets as {1,2,3} or {1,5}
 
   then the fibonacci number just less than 6 is 5 so bit representing
 5 is
   set then for completing the sum to 6 bit 1 is also set.
   so *fibonacci representation of 6 is 1001 .* not 0111
 
   ATul Singh | Final Year  | Computer Science  Engineering | NIT
   Jalandhar  | 9530739855 |
 
--
   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
   algogeeks+unsubscr...@googlegroups.com.
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Google written test

2012-03-17 Thread Gene
It looks from the example like you pick the largest (as if the digits
were a binary number).  Here's what I get:

#include stdio.h

unsigned f(unsigned n, unsigned fi, unsigned fim1)
{
  if (fi  n) return n;
  unsigned r = f(n, fi + fim1, fi);
  if (r = fi) {
putchar('1');
return r - fi;
  }
  putchar('0');
  return r;
}

int main(int argc, char *argv[])
{
  unsigned n;
  if (argc  1  sscanf(argv[1], %u, n) == 1) {
f(n, 1, 0);
putchar('\n');
  }
  return 0;
}


On Mar 17, 2:08 pm, Ravi Ranjan ravi.cool2...@gmail.com wrote:
 @ if for a given number more than 1 answer exist then whats the answer???

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Google written test

2012-03-17 Thread Gene
It looks from the example like you pick the largest (as if the digits
were a binary number).  Here's what I get:

#include stdio.h

unsigned f(unsigned n, unsigned fi, unsigned fim1)
{
  if (fi  n) return n;
  unsigned r = f(n, fi + fim1, fi);
  if (r = fi) {
putchar('1');
return r - fi;
  }
  putchar('0');
  return r;
}

int main(int argc, char *argv[])
{
  unsigned n;
  if (argc  1  sscanf(argv[1], %u, n) == 1) {
f(n, 1, 1);
putchar('\n');
  }
  return 0;
}

On Mar 17, 2:08 pm, Ravi Ranjan ravi.cool2...@gmail.com wrote:
 @ if for a given number more than 1 answer exist then whats the answer???

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.