Pensieve header: October 16: The Towers of Hanoi Puzzle.

Today. The Towers of Hanoi, then whatever you may suggest, then EIWL 9-12, then, if time, Patterns.

Topics (in no particular order). Whatever you may suggest; whatever comes to my mind; the Fibonacci numbers; the Catalan numbers; the Jones polynomial; a more efficient Jones algorithm; a riddle on spheres; Khovanov homology; Γ-calculus; the Hopf fibration; Hilbert’s 13th problem; non-commutative Gaussian elimination; free Lie algebras; the Baker-Campbell-Hausdorff formula; wacky numbers; an order 4 torus; the Schwarz Lantern; knot colourings; the Temperley-Lieb pairing; the dodecahedral link; sound experiments; barycentric subdivisions; a Peano curve; braid closures and Vogel’s algorithm; the insolubility of the quintic; phase portraits; the Mandelbrot set; shadows of the Cantor aerogel; quilt plots; some image transformations; De Bruijn graphs; the Riemann series theorem; finite type invariants and the Willerton fish; the Towers of Hanoi; Hochschild homology of (some) coalgebras; convolutions and image improvements.

An Image Manipulation Challenge

The image at http://drorbn.net/bbs/show?shot=17-1750-171013-121553.jpg is pathetic. Can you improve it? Whatever you do, should also work well with all other images at http://drorbn.net/bbs/show.php?prefix=17-1750.

The Towers of Hanoi

move[1,a_,b_,c_]:= Print["Move #1 from ",a, " to ",c];
move[n_,a_,b_,c_]:= (
move[n-1,a,c,b];
Print["Move #",n," from ",a, " to ",c];
move[n-1,b,a,c]
)

move[3, A,B,C]

move[0,a_,b_,c_]:= Null;
move[n_,a_,b_,c_]:= (
move[n-1,a,c,b];
Print["Move #",n," from ",a, " to ",c];
move[n-1,b,a,c]
)

move[3, A,B,C]

? /;

Range[10] /. {k_Integer /; k<7 :> (k^2)}

move1[n_,a_,b_,c_] /; n≥1:= (
move1[n-1,a,c,b];
Print["Move #",n," from ",a, " to ",c];
move1[n-1,b,a,c];
)

move1[3, A,B,C]

NotebookGet[EvaluationNotebook[]];

?Sow

?Reap

Reap[1+1; Sow[7]; 2+2; Sow[3+3]; 5+5]

move2[n_,a_,b_,c_] /; n≥1:=(
move2[n-1,a,c,b];
Sow@{n,a,c};
move2[n-1,b,a,c];
)

Reap[move2[3,A,B,C]]

move3[n_,a_,b_,c_] /; n≥1:=(
move3[n-1,a,c,b];
Sow@{n,a,c};
move3[n-1,b,a,c];
);
move3[n_] := Reap[move3[n,A,B,C]][[2,1]]

move3[4]

move4[n_,a_,b_,c_] /; n≥1:=(
move4[n-1,a,c,b];
AppendTo[moves, {n,a,c}];
move4[n-1,b,a,c];
);
move4[n_] :=(moves={}; move4[n,A,B,C]; moves)

move4[3]

move5[n_,a_,b_,c_] /; n≥1:=(
move5[n-1,a,c,b];
state[[a]]=Most[state[[a]]];
AppendTo[state[[c]],n];
Sow@state;
move5[n-1,b,a,c];
);
move5[n_] := (
state={Tower@@Reverse[Range[n]], Tower[], Tower[]};
Reap[Sow[state]; move5[n,1,2,3]][[2,1]]
)

move5[5]

Reverse[{1,2,3}]

?Append

rev[{}]={};
rev[l_List] := Append[rev[Rest[l]], First[l]]

rev[{"A", 4, π}]

rev2[{}]={};
rev2[l_List] /; l=!={} := Append[rev2[Rest[l]], First[l]]

rev2[Range[5]]

rev3[{}]={};
rev3[{f_, r___}] := Append[rev3[{r}], f]

rev3[{1,2,3}]