Skip to content

Instantly share code, notes, and snippets.

@toddsundsted
Created October 6, 2014 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddsundsted/b6ab0bfe693ae13056d6 to your computer and use it in GitHub Desktop.
Save toddsundsted/b6ab0bfe693ae13056d6 to your computer and use it in GitHub Desktop.
Haskell H/W: Tower of Hanoi
type Peg = String
type Move = (Peg, Peg)
move :: Integer -> Peg -> Peg -> Peg -> [Move]
move 0 _ _ _ = []
move 1 from to _ = [(from,to)]
move n from to temp = move (n - 1) from temp to ++ [(from,to)] ++ move (n - 1) temp to from
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
hanoi n a b c = move n a c b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment