(************************************************************ hanoi.ml Created : Thu Aug 29 20:14:06 2002 Last modified: Fri Aug 30 10:15:27 2002 Compile: ocamlopt.opt hanoi.ml -o hanoi # ************************************************************) (** *) (*** ↑ Hanoi モジュールの説明になるはず。空 ***) (** 輪を f 番の塔から t 番の塔へ移動する。ここをアニメーションすると 少しは楽しい....か? *) let move f t = Printf.printf "move(%d,%d)\n" f t (** f 番の塔の山を t 番の塔に移す *) let rec hanoi f t m n = if n = 1 then move f t else begin hanoi f m t (n-1); move f t; hanoi m t f (n-1); end let _ = hanoi 0 2 1 3;