00000000: 0D 50 52 4F 47 52 41 4D 20 48 41 4E 4F 49 28 49 |.PROGRAM HANOI(I|
00000010: 4E 50 55 54 2F 2C 4F 55 54 50 55 54 29 3B 0D 56 |NPUT/,OUTPUT);.V|
00000020: 41 52 0D 58 2C 54 4F 54 41 4C 3A 49 4E 54 45 47 |AR.X,TOTAL:INTEG|
00000030: 45 52 3B 0D 50 52 4F 43 45 44 55 52 45 20 4D 4F |ER;.PROCEDURE MO|
00000040: 56 45 54 4F 57 45 52 28 48 45 49 47 48 54 2C 46 |VETOWER(HEIGHT,F|
00000050: 52 4F 4D 4E 45 45 44 4C 45 2C 54 4F 4E 45 45 44 |ROMNEEDLE,TONEED|
00000060: 4C 45 2C 55 53 49 4E 47 4E 45 45 44 4C 45 3A 49 |LE,USINGNEEDLE:I|
00000070: 4E 54 45 47 45 52 29 3B 20 20 0D 50 52 4F 43 45 |NTEGER); .PROCE|
00000080: 44 55 52 45 20 4D 4F 56 45 44 49 53 4B 28 54 41 |DURE MOVEDISK(TA|
00000090: 4B 45 4F 46 46 2C 50 55 54 4F 4E 3A 49 4E 54 45 |KEOFF,PUTON:INTE|
000000A0: 47 45 52 29 3B 0D 42 45 47 49 4E 0D 58 3A 3D 58 |GER);.BEGIN.X:=X|
000000B0: 2B 31 3B 0D 57 52 49 54 45 4C 4E 28 27 20 20 20 |+1;.WRITELN(' |
000000C0: 20 20 27 2C 54 41 4B 45 4F 46 46 2C 27 20 54 4F | ',TAKEOFF,' TO|
000000D0: 20 27 2C 50 55 54 4F 4E 3A 31 29 0D 45 4E 44 3B | ',PUTON:1).END;|
000000E0: 0D 20 20 42 45 47 49 4E 28 2A 4D 4F 56 45 54 4F |. BEGIN(*MOVETO|
000000F0: 57 45 52 2A 29 0D 49 46 20 48 45 49 47 48 54 3E |WER*).IF HEIGHT>|
00000100: 30 0D 20 20 20 54 48 45 4E 0D 20 20 20 42 45 47 |0. THEN. BEG|
00000110: 49 4E 0D 20 20 20 4D 4F 56 45 54 4F 57 45 52 28 |IN. MOVETOWER(|
00000120: 48 45 49 47 48 54 2D 31 2C 46 52 4F 4D 4E 45 45 |HEIGHT-1,FROMNEE|
00000130: 44 4C 45 2C 55 53 49 4E 47 4E 45 45 44 4C 45 2C |DLE,USINGNEEDLE,|
00000140: 54 4F 4E 45 45 44 4C 45 29 3B 0D 20 20 20 20 20 |TONEEDLE);. |
00000150: 20 20 20 4D 4F 56 45 44 49 53 4B 28 46 52 4F 4D | MOVEDISK(FROM|
00000160: 4E 45 45 44 4C 45 2C 54 4F 4E 45 45 44 4C 45 29 |NEEDLE,TONEEDLE)|
00000170: 3B 0D 20 20 20 20 20 20 20 20 4D 4F 56 45 54 4F |;. MOVETO|
00000180: 57 45 52 28 48 45 49 47 48 54 2D 31 2C 55 53 49 |WER(HEIGHT-1,USI|
00000190: 4E 47 4E 45 45 44 4C 45 2C 54 4F 4E 45 45 44 4C |NGNEEDLE,TONEEDL|
000001A0: 45 2C 46 52 4F 4D 4E 45 45 44 4C 45 29 0D 45 4E |E,FROMNEEDLE).EN|
000001B0: 44 0D 45 4E 44 3B 0D 42 45 47 49 4E 28 2A 48 41 |D.END;.BEGIN(*HA|
000001C0: 4E 4F 49 2A 29 0D 20 20 20 58 3A 3D 30 3B 0D 20 |NOI*). X:=0;. |
000001D0: 20 20 57 52 49 54 45 4C 4E 3B 0D 20 20 20 57 52 | WRITELN;. WR|
000001E0: 49 54 45 4C 4E 28 27 57 48 41 54 20 48 45 49 47 |ITELN('WHAT HEIG|
000001F0: 48 54 20 3F 27 29 3B 0D 20 20 20 52 45 41 44 28 |HT ?');. READ(|
00000200: 54 4F 54 41 4C 29 3B 0D 20 20 20 4D 4F 56 45 54 |TOTAL);. MOVET|
00000210: 4F 57 45 52 28 54 4F 54 41 4C 2C 31 2C 33 2C 32 |OWER(TOTAL,1,3,2|
00000220: 29 3B 0D 20 20 20 57 52 49 54 45 4C 4E 3B 0D 20 |);. WRITELN;. |
00000230: 20 20 57 52 49 54 45 4C 4E 28 27 4E 55 4D 42 45 | WRITELN('NUMBE|
00000240: 52 20 4F 46 20 43 48 41 4E 47 45 53 27 2C 58 29 |R OF CHANGES',X)|
00000250: 0D 20 20 20 45 4E 44 2E 0D 20 03 66 50 E0 8E |. END.. .fP.. |
.PROGRAM HANOI(INPUT/,OUTPUT);.VAR.X,TOT
AL:INTEGER;.PROCEDURE MOVETOWER(HEIGHT,F
ROMNEEDLE,TONEEDLE,USINGNEEDLE:INTEGER);
.PROCEDURE MOVEDISK(TAKEOFF,PUTON:INTE
GER);.BEGIN.X:=X+1;.WRITELN(' ',TAKE
OFF,' TO ',PUTON:1).END;. BEGIN(*MOVETO
WER*).IF HEIGHT>0. THEN. BEGIN. MO
VETOWER(HEIGHT-1,FROMNEEDLE,USINGNEEDLE,
TONEEDLE);. MOVEDISK(FROMNEEDLE,T
ONEEDLE);. MOVETOWER(HEIGHT-1,USI
NGNEEDLE,TONEEDLE,FROMNEEDLE).END.END;.B
EGIN(*HANOI*). X:=0;. WRITELN;. WR
ITELN('WHAT HEIGHT ?');. READ(TOTAL);.
MOVETOWER(TOTAL,1,3,2);. WRITELN;.
WRITELN('NUMBER OF CHANGES',X). END.
. .FP..
×
C64 Image
> CLICK IMAGE PREVIEW FOR FULL MODAL