Skip to content

Instantly share code, notes, and snippets.

@sandy98
Created February 7, 2016 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandy98/4bd7b7f1d5e285691939 to your computer and use it in GitHub Desktop.
Save sandy98/4bd7b7f1d5e285691939 to your computer and use it in GitHub Desktop.
Tower of Hanoi - Clojure(script) version.
(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