In the tower of Hanoi $x,y,z$ are the positions and we are to move 10 disks from $x$ to $y$. What are the 128th and 768th moves?
(A) $x\to y$ and $x\to z$
(B) $x\to z$ and $z\to x$
(C) $x\to z$ and $z\to y$
(D) $x\to y$ and $z\to y$
I know the total number of moves is $2^{10}-1=1023$. For move 128 I did $128\bmod3=2$, which gave me nothing at all… please help me out!
Try listing out the moves for one, two and three discs:
There is a pattern here that allows us to get the sequence of moves for the next number of discs:
ywithzand vice versa.xy.xwithzand vice versa.This allows us to find the source and destination pegs of the $k$th move of the $n$-disc sequence:
xandyrespectively. Write out $k$ as an $n$-bit binary word (zero-padded on the left) and place a pointer on the least significant1.0, replaceywithzand vice versa; if it lands on a1, replacexwithzand vice versa. Repeat step 2.Here, $n=10$, so the set-ups for finding the 128th and 768th moves are as follows:
Hence the correct answer is (d).
By the way, here's the algorithm for the 72nd move: