Created
February 22, 2015 00:42
-
-
Save callerobertsson/dc513ffd8fda593d6305 to your computer and use it in GitHub Desktop.
Haskell: Tower of Hanoi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, c)] ++ hanoi (n - 1) b a c | |
main = do | |
print $ hanoi 1 "a" "b" "c" | |
print $ hanoi 2 "a" "b" "c" | |
print $ hanoi 3 "a" "b" "c" | |
print $ hanoi 4 "a" "b" "c" | |
print $ length (hanoi 20 "a" "b" "c") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment