` File: HANOI.FC of Tape: Sources/Focal/fc3`
`(.FC,.FO Focal format converted to 'WRITE' listing) `

```C-PS/8 FOCAL, 1971

01.01 C     HANOI BY DEC
01.02 C     FROM 'PROGRAMMING LANGUAGES'
01.03 C     LAST CHANGE: 8/7/71
01.04
01.05 C     THIS PROGRAM WORKS WITH THE TOWERS OF HANOI PROBLEM.
01.06 C YOU ARE GIVEN THREE TOWERS WITH VARIOUS SIZED DISCS ON
01.07 C ONE OF THEM.  THE OBJECT IS TO PLACE ALL THE DISCS ON
01.08 C ANOTHER TOWER ON AT A TIME, WITH THE STIPULATION THAT A
01.09 C LARGER DISC MAY NEVER BE ON TOP OF A SMALLER ONE.  THIS
01.10 C PROGRAM IS GOOD FOR ANY NUMBER OF DISCS AND CAN BE RUN
01.11 C EITHER IN MANUAL (YOU TELL IT WHERE TO MOVE) OR AUTOMATIC
01.12 C MODE.  IT WILL ALSO EXPLAIN ITS MOVES OR DRAW THE FOR YOU,
01.13 C DEPENDING ON HOW YOU ANSWER THE 'MOVES OR PLOTS' QUESTION.
01.14 C ** OUT DISC IS THE DISC (1 ON TOP) THAT YOU WANT TO MOVE
01.15 C ** IN DISC IS THE POSITION (1 ON TOP) WHERE YOU MOVE TO
01.16 C ** OUT TOWER IS THE TOWER (1 ON LEFT) FROM WHICH YOU MOVE
01.17 C ** IN TOWER IS THE TOWER (3 ON RIGHT) YOU MOVE TO
01.18 C THIS PROGRAM ASSUMES NO CHEATING, AND DOES NOT CHECK FOR IT.
01.19
01.29 E
01.30 A "NO. OF DISKS? "N,!
01.40 F I=1,N;S SS(I)=I
01.50 S SO=1;S SI=3
01.60 S NO=N;S NI=N;S I=0
01.70 A "MOVES OR PLOTS? ",MOVE,!
01.80 I (FABS(MO-0MOVES)) ,1.85;D 23
01.85 A "AUTO OR MANUAL? ",A,!
01.90 I (FABS(A-0MANUAL)),5.1;D 2;T !!"DONE !",!!;Q

02.20 I [SS<(SO-1)*N+NO-1>]ER,2.95
02.30 S I=I+1;S NO(I)=NO;S SO(I)=SO;S SI(I)=SI
02.50 S SI=6-SO-SI;S NO=NO-1;D 3;S TE(I)=NI;D 2
02.60 S SI=SI(I);S NO=NO+1;D 3;D 6
02.70 S SO=6-SO-SI;S NO=TE(I);D 3;D 2
02.80 S SI=SI(I);S SO=SO(I);S NO=NO(I);S I=I-1
02.90 R
02.95 D 3;D 6;R

03.10 S NI=N
03.20 I [SS((SI-1)*N+NI)]ER,3.3;S NI=NI-1;G 3.2
03.30 R

05.10 A "OUT-DISC: ",NO,"TOWER: ",SO
05.20 A !"IN-DISC: ",NI,"TOWER: ",SI,!;D 6
05.30 S A=0
05.40 F I=1,N*2;S A=A+SS(I)
05.50 I (-A) 5.1;T !"WELL DONE!"!;Q

06.10 S DO=(SO-1)*N+NO
06.20 S DI=(SI-1)*N+NI
06.30 S SS(DI)=SS(DO)
06.40 S SS(DO)=0
06.50 I (MOVE)ER,6.7;D 23;R
06.70 T !%2,?SO,   NO,!SI,   NI,?!

23.10 F J=1,N;T !;F K=0,70;D 23.3
23.20 T !!!!;R
23.30 I [K-15+SS(J)*2]23.6;I (-K+15+SS(J)*2)23.6;T "#
23.60 I (K-35+SS(J+N)*2) 23.7;I (-K+35+SS(J+N)*2) 23.7;T "#
23.70 I (K-55+SS(J+N+N)*2) 23.8;I (-K+55+SS(J+N+N)*2)23.77;T "#
23.77 S K=100;R
23.80 T " "
```