Skip to content

Instantly share code, notes, and snippets.

@ignacy
Created May 24, 2015 16:49
Show Gist options
  • Select an option

  • Save ignacy/f99bcdad951e8c252b94 to your computer and use it in GitHub Desktop.

Select an option

Save ignacy/f99bcdad951e8c252b94 to your computer and use it in GitHub Desktop.
Towers of Hanoi in haskell
module TowersOfHanoi where
type Peg = String
type Move = (Peg, Peg)
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
hanoi 0 _ _ _ = []
hanoi n a b c = (hanoi (n - 1) a c b) ++ [(a, b)] ++ (hanoi (n - 1) c b a)
@ignacy
Copy link
Copy Markdown
Author

ignacy commented May 24, 2015

hanoi 2 "a" "b" "c" == [("a","c"), ("a","b"), ("c","b")]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment