Skip to content

Instantly share code, notes, and snippets.

@GrooveStomp
Created June 4, 2014 05:32
Show Gist options
  • Select an option

  • Save GrooveStomp/a02cabe16a1746741b32 to your computer and use it in GitHub Desktop.

Select an option

Save GrooveStomp/a02cabe16a1746741b32 to your computer and use it in GitHub Desktop.
Towers of Hanoi (3 Pegs)
type Peg = String
type Move = (Peg, Peg)
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
hanoi 1 p1 p2 _ = [(p1, p2)]
hanoi n p1 p2 p3 = hanoi (n - 1) p1 p3 p2 ++ [(p1, p2)] ++ hanoi (n - 1) p3 p2 p1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment