kernelthread.com

Scheme

The Towers of Hanoi implemented in Scheme.

;; ;; The Towers Of Hanoi ;; Scheme ;; Copyright (C) 1998 Amit Singh. All Rights Reserved. ;; http://hanoi.kernelthread.com ;; ;; Tested under FSF Scheme (scm) version 5c1 ;; Load this file in scm using `scm -il<thisfile>' ;; Then invoke the hanoi function as follows: ;; (hanoi N) ;; where N is replaced by an integer (define (dohanoi n to from using) (if (> n 0) (begin (dohanoi (- n 1) using from to) (display "move ") (display from) (display " --> ") (display to) (newline) (dohanoi (- n 1) to using from) #t ) #f ) ) (define (hanoi n) (dohanoi n 3 1 2) )

Download

hanoi.scm