http://t3x.org/klisp/klsys/hanoi

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