home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
forum3.lzh
/
LISP
/
hanoi.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1987-11-19
|
448b
|
25 lines
; Good ol towers of hanoi
;
; Usage:
; (hanoi <n>)
; <n> - an integer the number of discs
(defun hanoi(n)
( transfer 'A 'B 'C n ))
(defun print-move ( from to )
(princ "Move Disk From ")
(princ from)
(princ " To ")
(princ to)
(princ "\n"))
(defun transfer ( from to via n )
(cond ((equal n 1) (print-move from to ))
(t (transfer from via to (- n 1))
(print-move from to)
(transfer via to from (- n 1)))))