; Returns number of moves to solve k-disc puzzle (define (hanoi k) (if (= k 1) 1 (+ (* 2 (hanoi (- k 1))) 1))) ; Returns the auxillary pole given source a and ; destination b (define (auxillary a b) (let ((s (+ a b))) (cond ((= s 1) 2) ((= s 3) 0) ((= s 2) 1)))) ; Prints moves required to solve k-disc puzzle ; k = number of discs ; a = source pole (0, 1, or 2) ; b = destination pole (0, 1, or 2, not equal to source pole) (define (hanoi2 k a b) (if (= k 1) (printf "Pole ~a to pole ~a\n" a b) (begin (hanoi2 (- k 1) a (auxillary a b)) (printf "Pole ~a to pole ~a\n" a b) (hanoi2 (- k 1) (auxillary a b) b))))