Post Reply 
(34C) Hanoi Towers - Automatic & Manual resolutions
01-22-2020, 12:42 AM (This post was last modified: 01-22-2020 12:46 AM by Archilog.)
Post: #1
(34C) Hanoi Towers - Automatic & Manual resolutions
Here is a program to solve the classical Hanoi Towers problem with your HP-34C.

How can I use it?
There are two ways to proceed:
- You let the HP compute each move (Press A - "A" for "Automatic");
- You try to be faster! (Press B - "B" for "Be faster!").

In automatic mode, the HP-34C will display every reception tower (for example 3.1 for the third tower with the smallest disk) until the last (3.987654321) move. This version will last more than two hours (2 h 8 m 32 s on my HP-34C S/N 2117S....), this counter-performance being partly due to display management (only disks are displayed from each register, not zeroes).

If you decide to challenge your calculator, it will display at each turn the three towers, waiting for your answer:
- Enter the first tower,
- Press [ENTER],
- Enter the second tower,
- Press [R/S].

Like in real life, there is no control of the validity of your choice.
If you want to check the towers state again before playing, press [FIX] [9] and then recall one of the third first registers ([RCL] [1], [2] or [3]): content will be display as 9.987654321 for example, where the integer represents the disks cardinal number in the register. Once that is done, proceed as usual.

Example:
The HP-34C displays successively: 1.987654321, 2., 3.,
then waits for your inputs, for instance:
[1] [ENTER] [3] [R/S],
The calculator displays: 1.98765432, 2., 3.1,
Your next move:
[1] [ENTER] [2] [R/S], etc.

At the end of the game, register 0 contains the number of your moves. Congratulations!
(I did that once upon a time... well, it was pretty hard, you can believe me...)

Note: if you want to pause the game in B mode, just turn off the calculator when it is waiting for your move.
After a while, turn it on again, press [GTO] [.] [0] [2] [2] and enter your move as usual.


Program:
(part I)
Code:

001 LBL A    011 STO-1    021 GSB 3    031 GTO 8    041 R↓       051 GSB 7    061 x<=y?    071 *        081 STO 0    091 R↓
002 SF0      012 1        022 R/S      032 LBL 9    042 GSB 5    052 GSB 4    062 GSB 7    072 2        082 GSB I    092 RTN
003 LBL B    013 STO I    023 x↔y      033 GSB 4    043 R↓       053 STO 0    063 x=0?     073 /        083 RCL 0    093 LBL 6
004 CLReg    014 F?0      024 x↔I      034 .        044 GSB 7    054 GSB 7    064 GSB 7    074 FRAC     084 STO I    094 RCL(i)
005 1        015 GTO 9    025 R↓       035 1        045 GSB 6    055 GSB 4    065 GSB 4    075 x=0?     085 GTO 9    095 INT
006 0        016 LBL 8    026 GSB 4    036 x=y?     046 RCL I    056 x=0?     066 GSB 5    076 GSB 7    086 LBL 7    096 Lst x
007 STO+1    017 1        027 GSB 5    037 GTO 0    047 STO 0    057 1        067 R↓       077 GSB 7    087 DSE      097 x↔y
008 8        018 STO+0    028 x↔I      038 GSB 7    048 GSB I    058 RCL 0    068 ENTER    078 R↓       088 RTN      098 10^x
009 1        019 GSB 1    029 R↓       039 GTO 9    049 RCL 0    059 x<=y?    069 1        079 GSB 6    089 3        099 *
010 1/x      020 GSB 2    030 GSB 6    040 LBL 0    050 STO I    060 GSB 7    070 0        080 RCL I    090 STO I    100 Lst x

(part II)
Code:

101 R↓       111 GTO 6    121 x↔y      131 INT      141 ENTER    151 LBL 2    161 x↔I     171 RTN |          VARIABLES         |
102 +        112 RTN      122 /        132 1        142 FRAC     152 RCL 2    162 3        _______|   [A] mode  ::  [B] mode   | 
103 R↑       113 LBL 6    123 Lst x    133 -        143 RTN      153 INT      163 GSB 0   |   R0 -> Compar. Dec.:: Moves number|
104 /        114 FIX 9    124 LOG      134 10^x     144 LBL 1    154 x↔I      164 RTN     |   R1 -> T1 (Disks number, disks)   |
105 1        115 6        125 +        135 RCL(i)   145 RCL 1    155 2        165 LBL 0   |   R2 -> T2 (Disks number, disks)   |
106 +        116 -        126 STO(i)   136 FRAC     146 INT      156 GSB 0    166 Lst x   |   R3 -> T3 (Disks number, disks)   |
107 STO(i)   117 R/S      127 R↓       137 x↔y      147 x↔I      157 RTN      167 FRAC    |   RI -> Disp. manag.::  Display    |
108 9        118 LBL 5    128 RTN      138 *        148 1        158 LBL 3    168 +       |   RI -> /T. select. :: management  |
109 RCL 3    119 R↓       129 LBL 4    139 Lst x    149 GSB 0    159 RCL 3    169 DSP I   | -----------------------------------|
110 x>y?     120 INT      130 RCL(i)   140 x↔y      150 RTN      160 INT      170 PSE     |  171 s., 5 registers : 206 bytes   |

This program was first published there some weeks ago.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)