Towers of Hanoi: Difference between revisions

Content added Content deleted
Line 1,758: Line 1,758:
hanoi n a b c = hanoi (n-1) a c b ++ [(a,b)] ++ hanoi (n-1) c b a</lang>
hanoi n a b c = hanoi (n-1) a c b ++ [(a,b)] ++ hanoi (n-1) c b a</lang>


You can also do the above with tail-recursion:
You can also do the above with one tail-recursion call:
<lang haskell>hanoi :: Integer -> a -> a -> a -> [(a, a)]
<lang haskell>hanoi :: Integer -> a -> a -> a -> [(a, a)]