Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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