Towers of Hanoi
Ladies and Gentlemen! Welcome to DekuDekuplex’s Blog, the Never Never Land of amateur functional programming theory!
What is the value of a process that doesn’t terminate?
Allow me to present my introductory Scheme procedure, Towers of Hanoi:
;; Towers of Hanoi, plt1.1 ;; PLT-Scheme-specific Version 1.1 of Towers of Hanoi ;; ;; Copyright(C) April 02, 2008, at 19:38, ;; by Benjamin L. Russell (define (hanoi n) (hanoi-helper 'A 'B 'C n)) (define (hanoi-helper source using destination n) (cond ((= n 1) (printf "Moving from disc ~a to ~a.\n" source destination)) (else (hanoi-helper source destination using (- n 1)) (hanoi-helper source using destination 1) (hanoi-helper using source destination (- n 1)))))
To run the Scheme source code above, simply type:
(hanoi 3)
You shall be rewarded with:
Moving from disc A to C. Moving from disc A to B. Moving from disc C to B. Moving from disc A to C. Moving from disc B to A. Moving from disc B to C. Moving from disc A to C.
Wonderful, isn’t it?
So much for now. Until next time….
(lambda x.(x x))(lambda x.(x x))
Trackbacks & Pingbacks