Created
February 7, 2016 11:12
-
-
Save sandy98/4bd7b7f1d5e285691939 to your computer and use it in GitHub Desktop.
Tower of Hanoi - Clojure(script) version.
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
(defn hanoi | |
([n] (hanoi n 1 2 3 '())) | |
([n from aux to moves] | |
(if (= 1 n) (cons (list from to) moves) | |
(let [moves (hanoi (dec n) aux from to moves)] | |
(let [moves (cons (list from to) moves)] | |
(let [moves (hanoi (dec n) from to aux moves)] | |
moves)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment