Skip to content

Instantly share code, notes, and snippets.

@mahasak
Last active November 18, 2020 15:32
Show Gist options
  • Save mahasak/632950732428a45a48eb69fd778c04d0 to your computer and use it in GitHub Desktop.
Save mahasak/632950732428a45a48eb69fd778c04d0 to your computer and use it in GitHub Desktop.
Tower of Hanoi
hanoi :: Int -> [(Int,Int)]
hanoi n = hanoi' n 1 2 3
hanoi' 0 _ _ _ []
hanoi' n src temp dest = top_to_temp ++ botton_to_dest : top_to_dest
where top_to_temp = hanoi' (n-1) src dest temp
bottom_to_dest = (src, dest)
tops_to_dest = (hanoi' (n-1) temp src dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment