Hanoi Towers

Description

A program to solve the classical Hanoi Towers problem.
Originally for the HP-34C (HP Forums / HP Software Libraries / General Software Library)

How can I use it?
There are two ways to proceed:

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:
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 f 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-15C 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 CHS 0 2 2 and enter your move as usual.

Program Resources

Labels

Name Description Name Description
 A Let the HP compute each move  4 #
 B You try to be faster!  5 #
 0 #  6 #
 1 #  7 #
 2 #  8 #
 3 #  9 #

Storage Registers

Name Description
 0 Number of your moves (At the end of the game)
 1
 2
 3
(i)
I

Flags

Number Description
0

Program

Line Display Key Sequence Line Display Key Sequence Line Display Key Sequence
000 058 45 0 RCL 0 116 30
001 42,21,11 f LBL A 059 43 10 g x≤y 117 31 R/S
002 43, 4, 0 g SF 0 060 32 7 GSB 7 118 42,21, 5 f LBL 5
003 42,21,12 f LBL B 061 43 10 g x≤y 119 33 R⬇
004 42 34 f REG 062 32 7 GSB 7 120 43 44 g INT
005 1 1 063 43 20 g x=0 121 34 x↔y
006 0 0 064 32 7 GSB 7 122 10 ÷
007 44,40, 1 STO + 1 065 32 4 GSB 4 123 43 36 g LSTΧ
008 8 8 066 32 5 GSB 5 124 43 13 g LOG
009 1 1 067 33 R⬇ 125 40 +
010 15 1/x 068 36 ENTER 126 44 24 STO (i)
011 44,30, 1 STO 1 069 1 1 127 33 R⬇
012 1 1 070 0 0 128 43 32 g RTN
013 44 25 STO I 071 20 × 129 42,21, 4 f LBL 4
014 43, 6, 0 g F? 0 072 2 2 130 45 24 RCL (i)
015 22 9 GTO 9 073 10 ÷ 131 43 44 g INT
016 42,21, 8 f LBL 8 074 42 44 f FRAC 132 1 1
017 1 1 075 43 20 g x=0 133 30
018 44,40, 0 STO + 0 076 32 7 GSB 7 134 13 10ˣ
019 32 1 GSB 1 077 32 7 GSB 7 135 45 24 RCL (i)
020 32 2 GSB 2 078 33 R⬇ 136 42 44 f FRAC
021 32 3 GSB 3 079 32 6 GSB 6 137 34 x↔y
022 31 R/S 080 45 25 RCL I 138 20 ×
023 34 x↔y 081 44 0 STO 0 139 43 36 g LSTΧ
024 42, 4,25 f Χ↔ I 082 32 25 GSB I 140 34 x↔y
025 33 R⬇ 083 45 0 RCL 0 141 36 ENTER
026 32 4 GSB 4 084 44 25 STO I 142 42 44 f FRAC
027 32 5 GSB 5 085 22 9 GTO 9 143 43 32 g RTN
028 42, 4,25 f Χ↔ I 086 42,21, 7 f LBL 7 144 42,21, 1 f LBL 1
029 33 R⬇ 087 42, 5, 1 f DSE 1 145 45 1 RCL 1
030 32 6 GSB 6 088 43 32 g RTN 146 43 44 g INT
031 22 8 GTO 8 089 3 3 147 42, 4,25 f Χ↔ I
032 42,21, 9 f LBL 9 090 44 25 STO I 148 1 1
033 32 4 GSB 4 091 33 R⬇ 149 32 0 GSB 0
034 48 . 092 43 32 g RTN 150 43 32 g RTN
035 1 1 093 42,21, 6 f LBL 6 151 42,21, 2 f LBL 2
036 43,30, 5 g TEST x=y 094 45 24 RCL (i) 152 45 2 RCL 2
037 22 0 GTO 0 095 43 44 g INT 153 43 44 g INT
038 32 7 GSB 7 096 43 36 g LSTΧ 154 42, 4,25 f Χ↔ I
039 22 9 GTO 9 097 34 x↔y 155 2 2
040 42,21, 0 f LBL 0 098 13 10ˣ 156 32 0 GSB 0
041 33 R⬇ 099 20 × 157 43 32 g RTN
042 32 5 GSB 5 100 43 36 g LSTΧ 158 42,21, 3 f LBL 3
043 33 R⬇ 101 33 R⬇ 159 45 3 RCL 3
044 32 7 GSB 7 102 40 + 160 43 44 g INT
045 32 6 GSB 6 103 43 33 g R⬆ 161 42, 4,25 f Χ↔ I
046 45 25 RCL I 104 10 ÷ 162 3 3
047 44 0 STO 0 105 1 1 163 32 0 GSB 0
048 32 25 GSB I 106 40 + 164 43 32 g RTN
049 45 0 RCL 0 107 44 24 STO (i) 165 42,21, 0 f LBL 0
050 44 25 STO I 108 9 9 166 43 36 g LSTΧ
051 32 7 GSB 7 109 45 3 RCL 3 167 42 44 f FRAC
052 32 4 GSB 4 110 43,30, 7 g TEST x>y 168 40 +
053 44 0 STO 0 111 22 6 GTO 6 169 45 25 RCL I
054 32 7 GSB 7 112 43 32 g RTN 170 42 31 f PSE
055 32 4 GSB 4 113 42,21, 6 f LBL 6 171 43 32 g RTN
056 43 20 g x=0 114 42, 7, 9 f FIX 9
057 1 1 115 6 6