Focal
The Towers of Hanoi as a Focal program.
01.10 c
01.20 c Towers Of Hanoi
01.30 c Focal
01.40 c Copyright (C) 2000 Amit Singh. All Rights Reserved.
01.50 c http://hanoi.kernelthread.com
01.60 c
01.70 c (Not that I am too proud of this code)
01.80 c
10.10 a "Enter number of disks", N
10.20 s M = 4096
10.30 f k = 1, M; s stack(k) = 0
10.40 s stack(1) = N
10.50 s stack(2) = 1
10.60 s stack(3) = 3
10.70 s stack(4) = 0
10.80 s sp = 4
10.90 t %1.0
20.10 f k = 1, M; do 30
30.1 if sp 40.10, 40.10; s processed = stack(sp)
30.2 s sp = sp - 1
30.3 s to = stack(sp)
30.4 s sp = sp - 1
30.5 s from = stack(sp)
30.6 s sp = sp - 1
30.7 s n = stack(sp)
30.8 s sp = sp - 1
30.9 s left = 6 - from - to
30.10 if processed 40.10, 30.21, 30.11
30.11 t "move "; t from; t " --> "; t to; t !
30.12 s sp = sp + 1
30.13 s stack(sp) = n - 1
30.14 s sp = sp + 1
30.15 s stack(sp) = left
30.16 s sp = sp + 1
30.17 s stack(sp) = to
30.18 s sp = sp + 1
30.19 s stack(sp) = 0
30.20 g 30.99
30.21 s m = n - 1
30.22 if m 40.10, 30.23, 30.25
30.23 t "move "; t from; t " --> "; t to; t !
30.24 g 30.99
30.25 s sp = sp + 1
30.26 s stack(sp) = n
30.27 s sp = sp + 1
30.28 s stack(sp) = from
30.29 s sp = sp + 1
30.30 s stack(sp) = to
30.31 s sp = sp + 1
30.32 s stack(sp) = 1
30.33 s sp = sp + 1
30.34 s stack(sp) = n - 1
30.35 s sp = sp + 1
30.36 s stack(sp) = from
30.37 s sp = sp + 1
30.38 s stack(sp) = left
30.39 s sp = sp + 1
30.40 s stack(sp) = 0
30.99 r
40.10 q