Howto program Hanoi statefree
[from a pattern-based perspective]


We can do a version of Towers of Hanoi with state
Well it would be convinient with a function f(nActual) that would tell us the move
as a function of nActual
We observe some wellknown facts. N is the number of rings
n is a counter for the total moves that is (N^2 -1)
nActual = current position in the sequence
0............nActual..........n = (N^2)-1.
We always step 1 step forward and the game's start-position is represented by 0.
The start position is represented by the number 0.
Then nActual increase with 1
and continue forward until nActual becomes n= (N^2)-1.


So Lets get to work and look for some patterns.




Look at the image above. Here we have 4 rings to start with.

As nActual progressive increses with 1 We observe a pattern of repititious movements
the 2 [x]'s under each colorblock suggests witch 2 poles
that are involved in moving a ring between them.
We observe an ever repeating AC, AB, BC pattern. But how to predict the direction of the next move ?.
Notice! The first 4 [from to movements] describes a pattern.
From A->C, A->B,C->B, A->C . But the 5. move B->A breaks that pattern !
So Although the pattern between is consistent
the direction [from to] isn't. So we cant know! We only observe it!. Not calculate it!
But the AC, AB, BC pattern will still help us. Even In a very impressive way too!

But for now lets consider numbers to represent nActual.
We know Base10 number system, but lets move down
to examine Base3 since there are 3 poles
Base2 since we move between 2 poles
Base1 to tell us if we get more information the lower the Base is.






But now!.Look at the depiction above. Here we have 4 different base number systems.
The * arragement represent the rings and their current pole-position.


We can see the Base 1 ( tally marks ) describing the rings position.
But how does it increase with 1 ?
Well! The way the tally marks are arraged here actualy depicts every position of the game
And it would provide us with the direction. It give us the [from to] direction simply by observing the actual tally mark
with the previous. Try it out yourself!

So now , whatever value nActual hold in the range 1 to (N^2)-1
we can use as argument to f(nActual) and have f return the move between.
the previous position [ nActual -1 ] and [ nActual ] itself.
So far so good.
But the way we arrange the tally marks contradicts the intent to investigate for lower complexity with lower base. Can you see why ?.
It is because the tally marks in this configuration actually ia a Base 16 number.
Base 16 in this tally mark form hold the solution in itself for N = 4. But not for another N. This way of finding a pattern is quickly
becoming impossible with increasing N
If N were 100 we would have to know a numbersystem with 10000 signs reperesenting 1 ... 10000.
Signs that by the way were the solution itself !. And would take up many pages of paper.

In short!, Tally marks or Base 1 number progression is hard to remember and unsuitable for f(nActual)

Base 10 have a progressive forward moving pattern. 1,2,3,.. and so on
But give us not enough translatable information on positions.

Base 3 have a progressive forward moving pattern 0000,0001,0002,0010,0011 .. etc.
But the 0's in base 3 do not accurately describe the number of rings on the initial A pole
as Base 2 does.

Base 2 have a wellknown progressive forward moving pattern 000,001,010,011 .. etc.
And indicate positions that possibly can be translated .
the initial 0 ,0 , 0, 0 , would then have to indicate 4 *'s on the A position.
The Base 2 leftmost 0's have a pattern of precisely counting the number of rings on A.
That is enough for us to look further into Base 2.







Here in this arrow diagram we look closer at base 2 movements arranged with C moved to the left side.
The arrows marked with red indicate where the pattern break.
The AC,AB,CB,AC direction folows a pattern but the ... BA breaks it.
Also the ODD and EVEN indications attempt to see if the number nActual in itself hold any info on the direction. Maybe. But it is super hard to find.






But remember the observation from the base 1 tally marks established that f(nActual) will have to look at [nActual] compared to the previous [nActual-1].
So lets move on and compare those up against eatchother. Here we see how perfect the binary numbers 0 and 1 count the number of rings
on the default and the destination pole. The * marked with red.
We also see the eternal repeating from pattern AAC ? BBA ? CCB ? AAC ? BBA..... etc
notice the ? is the value we have yet to calculate.
Also do not confuse this with the ever repeating AC, AB, BC pattern of invovlved poles.
The arrows point to the elements to be compared to decide From in the [From to] move
The 3 ? ? ? is known to become A A C and are marked with red background.
So do they reflect a general pattern?.
That can be testet. Let us compare the 3 ? in N = 4 with a different N. .
0 0 2 For N = 4. If You know programming you can produce the numbers for N = 6 yourself. Eventually with the c++ program in the link.
0 0 2 0 1 1 0 0 2 2 1 2 0 0 2 But no worries, here are the numbers For N = 6.
Even if we see 0 0 2 repeating in every second group of 3 , there are no useable pattern.





But so we anotate- with yellow color - the known [ from ] number pattern from the previous image
and search for patterns between [nActual-1] and nActual. As impossible it has been to extract any useful pattern from anything, it
is now amazing to observe, that not only do this image give us the answers
for the ? in AAC ? BBA ? CCB ? AAC, but in abundance give us the correct from
pattern for all values of [nActual].
When we logic AND the opposite 1's and use modolus 3. A perfect pattern.
So let's see if this amazing strike of luck also stand for ODD N's.




a link to solution in c++