Skip to content

Instantly share code, notes, and snippets.

@ctran
Last active August 29, 2015 14:13
Show Gist options
  • Save ctran/5b026410e89708690797 to your computer and use it in GitHub Desktop.
Save ctran/5b026410e89708690797 to your computer and use it in GitHub Desktop.
Tower of Hanoi
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