Hanoi Towers 
Vasiliki Liontou
12/6/2017

(* I tried to make a graphic representation of the Hanoi Towers. Initially, I wanted to color each disk with a different color that would be related to its dimentions so it would not change through the process but I could not find a way to do it. Do you have any suggestions?*)

H[1]:={1}
H[n_]:=H[n]=Join[H[n-1],{n},H[n-1]]

hanoi[1,i_,j_]:={{i,j}}
hanoi[n_,i_,j_]:=Join[hanoi[n-1,i,6-i-j],{{i,j}},hanoi[n-1,6-i-j,j]]

disp[t_,{i_,j_}]:=Module[{q=t,d},
d=First[(Subscript[q, [[i]]])];
(Subscript[q, [[i]]])=Rest[(Subscript[q, [[i]]])];
(Subscript[q, [[j]]])=Prepend[(Subscript[q, [[j]]]),d];
q]

towers[n_]:=FoldList[disp,{Range[n],{},{}},hanoi[n,1,3]]

h[n_,li_]:=Module[{y=-0.5},
{Map[(y=y+0.5;Rectangle[{-#,y},{#,y+0.5}])&, Reverse[li]]}]

shift[g_,x_]:=g/.Rectangle[r__]:>Rectangle@@Transpose[Transpose[{r}]+{x,0}]

Towers[{a_,b_,c_}]:=Module[{n=Length[Flatten[{a,b,c}]]},Graphics[{h[n,a],
RGBColor[1,0,0], shift[h[n,b],2n],
RGBColor[1,2,0], shift[h[n,c],4n]},
AspectRatio->Automatic,PlotRange->{{-n-.5,5n+1},{-1, n}}]
]

Show[GraphicsGrid[Transpose[Partition[movie=Towers/@towers[5],10]]],
ImageSize->500]