[TOWERS OF HANOI] ..PZ [M3] PFGKIFAFRDLFUFOFE@A6FG@E8FEZPF @&*!!!!!!TOWERS!OF!HANOI @&!!!BY!DANIEL!TEBBUTT#N!2001 @&# @&!!! !!V!! !! !!C!! !! !!C!! @&!!! !VVV! !! !!C!! !! !!C!! @&!!! VVVVV !! !!C!! !! !!C!! @&!!! !K1L! !! !K2L! !! !K3L! @& @&*DIAL!NUMBER!OF!COUNTERS!#K1A9LC ..PZ [M20 - one digit version] PZZKM2037FGKP10KPZT45KP@B2FQ ..PZ T56K [P6] GKA3FT25@H29@VFT4DA3@TFH30@S6@T1F V4DU4DAFG26@TFTFO5FA4DF4FS4F L4FT4DA1FS3@G9@EFSFO31@E20@J995FJF!F ..PZ [Towers of Hanoi Master] GK T47K P156@ TZ O1M [Prepare for output] O1M O2M O3M T80M [Store initial values: MOVE(n, position 1, pile 1, pile 3, pile 2 )] A5M T13M A12M T14M A4M T15M A6M T16M A5M T17M [Start of MOVE (number, called from, from pile , to pile , other pile)] T80M [Clear the accumulator] T78M [Set the counter to zero] T80M [Clear the accumulator] A86M [Form a transfer to top of stack command] A87M T22@ [Place the transfer command in the line 2 below this] A13M [Transfer a stored value onto the stack] PF A19@ [Increment the 'A(n)M' command in position 19@ to 'A(n+1)M'] A5M T19@ A21@ [Increment the 'A(n)M' command in position 21@ to 'A(n+1)M'] A5M T21@ A78M [Increment the counter by 2] A5M T78M A78M [If the counter is less than 8, then repeat this loop] S11M S4M G17@ T80M [Clear the accumulator] A86M [Increment the stack pointer] A11M A5M T86M A97M [Replace the altered lines of code in positions 19@ and 21@] T19@ A98M T21@ T80M [Clear the accumulator] A14M [If the number of counters to move is more than 1, then skip the following 13 lines] S6M E62@ T80M [Clear the accumulator] A15M [Print the 'from' number] TF A52@ G56F A16M [Print the 'to' number] TF A56@ G56F O2M [Print end-of-line] O3M G103@ [Go to the return section] E103@ T80M [Clear the accumulator] A7M [Store information in preparation for beginning the MOVE section MOVE(n-1,position 2, from pile, other pile, to pile)] T13M A14M S5M T14M A17M T85M A16M T17M A85M T16M G15@ [Go to the beginning of the MOVE section] E15@ T80M [Clear the accumulator] A9M [Store information in preparation for beginning the MOVE section MOVE(1,position 3, from pile, to pile, other pile)] T13M A5M T14M A15M T15M A16M T16M A17M T17M G15@ [Go to the beginning of the MOVE section] E15@ T80M [Clear the accumulator] A11M [Store information in preparation for beginning the MOVE section MOVE(n-1,position 4, other pile, to pile, from pile)] T13M A14M S5M T14M A17M T85M A15M T17M A85M T15M G15@ [Go to the beginning of the MOVE section] E15@ T80M [Clear the accumulator] A86M [Decrement the stack pointer] S11M S5M T86M A92M [Create an 'add number from top of stack' command] A86M T111@ [Keep the 'position' variable safe because it is needed later] PF T85M T80M [Clear the accumulator] T78M [Zero the counter] T80M [Clear the accumulator (the first time this point is reached this is unnecessary, but this point can be reached from other places)] A86M [Take the stack pointer - one record] S11M S5M A92M [Combine it to form an 'add number from stack' command] T121@ [Place this command in the line below] PF [Store the number from the stack] T13M A119@ [Increment the command in 119@ so that it points to a different part of the stack] A5M T119@ A122@ [Increment the command in 122@ so that it points to a different storage location] A5M T122@ A78M [Increment the counter] A5M T78M A78M [If the counter is less than 8 then repeat this section] S11M S4M G115@ T80M [Clear the accumulator] A99M [Replace the altered lines of code in 119@ and 122@] T119@ A100M T122@ T80M [Clear the accumulator] A85M [Check if the position MOVE was called from was position 1. If so, then go to the end of the program] S6M G155@ T80M [Clear the accumulator] A85M [If MOVE was called from position 2, return to the appropriate place] S8M G76@ T80M [Clear the accumulator] A85M [If MOVE was called from position 3, return to the appropriate place] S10M G89@ G103@ [MOVE must have been called from position 4, so return to the appropriate place] E103@ [ZF] [STOP DELETED] G512F [ENTER UI ROUTINE] PF [padding] #F [Characters for printing] @F &F P0D [numbers used in the program] P1F P1D P2F P2D P3F P3D P4F PH [!!!! Number of counters used, e.g. P3F = 3 counters !!!!] PF [Temporary storage locations] PF PF PF PF PF [Stack - sufficient for the calculations for up to 12 counters] PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF PF [used as 0] P55D [(Size of stack - 5) * 2 + 1] PF [Accumulator clears to here] A72M [Commands needed to replace altered code] T77M A23M T18M PF [Counter] PF [Stack pointer] T18M [Used with the stack pointer to construct commands about the stack] T19M T20M T21M T22M A18M A19M A20M A21M A22M A87M [Used to replace altered code] A13M A92M T13M EZPF