We can do a version of Towers of Hanoi with state
We can do a version without state from a pattern based perspective
Well if you have followed the previous ways to solve it, get ready for the real stuff.
You might have a customer that says yeah that is good and all, but i like to have a proven
matemathical solution. I don't want no bitwise and either. Then we are back at it again here.
would still be convinient with a function
f(
nActual,
N, a to c) that would tell us the move
as a function of
nActual ,
N , and if it is A->B or A->C.
We observe some wellknown facts.
N is the number of rings
n is a counter for the total moves that is (2^
N) -1
nActual = current position in the sequence
0............
nActual..........
n = (2^
N)-1.
We always step 1 step forward and the game's start-position is represented by 0.
As the start position is represented by the number 0.
we let
nActual represent the moves, let it start with 1'st move
and let it continue forward until
nActual
becomes
n = ( 2^
N)-1.
So Lets get to work and look for some math.