Oberon
The Towers of Hanoi as an Oberon program.
(* The Towers Of Hanoi *)
(* Oberon *)
(* Copyright (C) 1998 Amit Singh. All Rights Reserved. *)
(* http://hanoi.kernelthread.com *)
(* *)
(* Tested with o2c 1.16 on Linux *)
(* The implmentation consists of two modules, namely, *)
(* `Hanoi' and `Test'. They are given in a single file *)
(* here, and should be saved to `Hanoi.Mod' and `Test.Mod' *)
(* respectively. The number of disks is hardcoded in *)
(* `Test.Mod' to 3. That may be changed. *)
(* File: Hanoi.Mod -- begin -- *)
MODULE Hanoi;
IMPORT
CType, Out,
U := Unix;
PROCEDURE DoHanoi* (n, t, f, u: INTEGER);
VAR
res : CType.int;
BEGIN (* DoHanoi *)
IF n=0 THEN
RETURN;
END;
DoHanoi(n-1, u, f, t);
res := U.fputs ("move ", U.stdout);
Out.Int(f, 0);
res := U.fputs (" --> ", U.stdout);
Out.Int(t, 0);
res := U.fputc (10, U.stdout);
DoHanoi(n-1, t, u, f);
END DoHanoi;
END Hanoi.
(* File: Hanoi.Mod -- end -- *)
(* File: Test.Mod -- begin -- *)
MODULE Test;
IMPORT
Hanoi;
BEGIN
Hanoi.DoHanoi(3, 3, 1, 2);
END Test.
(* File: Test.Mod -- end -- *)