home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 01e / lisp211.zip / HANOI.L < prev    next >
Lisp/Scheme  |  1986-05-15  |  775b  |  34 lines

  1.  
  2. ;; HANOI.L for PC-LISP.EXE (V2.11)
  3. ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. ;;    Another program that was found with some XLISP stuff and modified to
  5. ;; run under PC-LISP. Again I do not know who the author is.
  6. ;;
  7. ;;           Peter Ashwood-Smith
  8. ;;           May 15th, 1986   
  9.   
  10.  
  11. ;;    Good ol towers of hanoi
  12. ;;
  13. ;;    Usage:
  14. ;;         (hanoi <n>)
  15. ;;             <n> - an integer the number of discs
  16.  
  17.  
  18. (defun hanoi(n)
  19.   ( transfer 'A 'B 'C n ))
  20.  
  21. (defun print-move ( from to )
  22.   (patom "Move Disk From ")
  23.   (patom from)
  24.   (patom " To ")
  25.   (patom to)
  26.   (patom "\n")
  27. )
  28.  
  29. (defun transfer ( from to via n )
  30.   (cond ((equal n 1) (print-move from to ))
  31.     (t (transfer from via to (1- n))
  32.        (print-move from to)
  33.        (transfer via to from (1- n)]     
  34.