Before moving into Types in Haskell which is one big chapter in this book I am following I thought of having some more familiarization with the language.

How about solving Tower of Hanoi problem through haskell?

hanoi (0, _, _, _) = []

hanoi (n,from,to,using) =

hanoi(n-1,from,using,to) ++

[(from, to)] ++

hanoi(n-1,using,to,from)

Running the program for n = 3 (3 discs) and 1, 2, 3 as the labels for from, using and to towers –

*Main> dohanoi (3,1,3,2)

[(1,3),(1,2),(3,2),(1,3),(2,1),(2,3),(1,3)]

If you just want the number of moves in the problem, take length of the list

length $ dohanoi (3,1,3,2)

This is equal to 2 ^ n – 1.