Towers of Hanoi

初めて始めてみた、あくまでも、悪魔でも、開くまでも書き続けてみます!

では、アクマデ、アマチュア関数学的プログラミング研究者として、小生の「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)))))

上記のSchemeソースコードを実行するには、先ず、DrScheme(http://www.csg.is.titech.ac.jp/~kourai/lecture/drscheme/drscheme.htmlhttp://download.plt-scheme.org/ 参照)をダウンロード・インストールし、その後、例えば、

(hanoi 3)

と入力すればいいのです。そうすれば、

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.

と返ってきます。

どうです?簡単ですが、素晴らしいでしょう!

では、今回はこの辺で・・・・・・。次回までお楽しみに。

あくまで、アマチュア関数型プログラミング研究者ですから・・・・・・。