In a slightly modified TOH we have 4 pegs. So in turn we have total of 4^N disk positions. Now in one of the solutions which I was going through, a given state is represented using below code -
for(int disc = 0; disc < N; disc++){
state += tower[disc]<<(disc*2);
}
tower[disc] --> tower where disc is currently located, which can be (0,1,2,3)
if I use N=3 in above code, it gives me 63, which is 4^N -1. So the formula works, i.e 0-63 all 64 positions can be represented. but I am not able to understand the mathematical correlation.
Can you please explain how above formula can represent all possible disk positions and how it will change if we further change number of pegs or N to lets say 5.