Last active
November 18, 2020 15:32
-
-
Save mahasak/632950732428a45a48eb69fd778c04d0 to your computer and use it in GitHub Desktop.
Tower of Hanoi
This file contains hidden or 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
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