http://t3x.org/klisp/klsys/hanoi.html   (light|dark)

KLSYS Example Programs

Towers of Hanoi

Towers of hanoi  |  Takeuchi function  |  Combinations of a set  |  Letrec macro

; Towers of Hanoi
; HANOI  - solve for N disks from X to Y via Z
; HANOI1 - solve for N disks

(defun hanoi (n x y z)
  (cond ((zerop n) nil)
        (t (append (hanoi (sub1 n) x z y)
                   (list (list x y))
                   (hanoi (sub1 n) z y x)))))

(defun hanoi1 (n)
  (hanoi n 'left 'middle 'right))
 

contact | privacy