See http://en.wikipedia.org/wiki/Tower_of_Hanoi#Binary_solutions

Dave

On Jun 9, 10:37 am, Jitendra Kushwaha <jitendra.th...@gmail.com>
wrote:
> Below iterative solution of the tower of hanoi problem...
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
>    int n, x;
>    printf( "How many disks? " );
>    scanf( "%d", &n );
>    printf("\n");
>    for (x=1; x < (1 << n); x++)
>       printf( "move from tower %i to tower %i.\n",
>                  (x&x-1)%3, ((x|x-1)+1)%3 );
> return 0;
>
> }
>
> i am not able to get how  "  (x&x-1)%3, ((x|x-1)+1)%3  "  is able to
> produce the output.What is the logic behind.
>
> Can anybody explain it???

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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.

Reply via email to