How does this work? Weird Towers of Hanoi Solution
问题 I was lost on the internet when I discovered this unusual, iterative solution to the towers of Hanoi: for (int x = 1; x < (1 << nDisks); x++) { FromPole = (x & x-1) % 3; ToPole = ((x | x-1) + 1) % 3; moveDisk(FromPole, ToPole); } This post also has similar Delphi code in one of the answers. However, for the life of me, I can\'t seem to find a good explanation for why this works. Can anyone help me understand it? 回答1: the recursive solution to towers of Hanoi works so that if you want to move