Towers of Hanoi: Difference between revisions

Content added Content deleted
m (fix bare lang tags)
(CoffeeScript)
Line 284: Line 284:
(println (format "Move from %s to %s" from to))
(println (format "Move from %s to %s" from to))
(recur (dec n) via to from))))</lang>
(recur (dec n) via to from))))</lang>

=={{header|CoffeeScript}}==

<lang coffeescript>
hanoi = (ndisks, start_peg=1, end_peg=3) ->
if ndisks
staging_peg = 1 + 2 + 3 - start_peg - end_peg
hanoi(ndisks-1, start_peg, staging_peg)
console.log "Move disk #{ndisks} from peg #{start_peg} to #{end_peg}"
hanoi(ndisks-1, staging_peg, end_peg)
hanoi(4)
</lang>



=={{header|Common Lisp}}==
=={{header|Common Lisp}}==