Next: , Previous: , Up: Benchmark Sources   [Contents][Index]


4.3.4 Hanoi

;;; C optimiser should be able to remove the first recursive call to
;;; move-them.  But Solaris 2.4 cc, gcc 2.5.8, and hobbit don't.
(define (hanoi n)
  (letrec ((move-them
            (lambda (n from to helper)
              (if (> n 1)
                  (begin
                    (move-them (- n 1) from helper to)
                    (move-them (- n 1) helper to from))))))
    (move-them n 0 1 2)))