Last active
August 29, 2015 14:13
-
-
Save ctran/5b026410e89708690797 to your computer and use it in GitHub Desktop.
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
import Text (..) | |
type alias Peg = String | |
type alias Move = (Peg, Peg) | |
hanoi: Int -> Peg -> Peg -> Peg -> List Move | |
hanoi n a b c = | |
if n == 0 then [] | |
else | |
let | |
step1 = hanoi (n - 1) a c b | |
step2 = (a, b) | |
step3 = hanoi (n - 1) c b a | |
in step1 ++ [step2] ++ step3 | |
main = asText (hanoi 3 "a" "b" "c") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment