19 - HANOI - Tower of Hanoi (with solver)

Post Reply
Peet
Posts: 91
Joined: Tue Sep 29, 2020 12:01 am
Location: Germany

19 - HANOI - Tower of Hanoi (with solver)

Post by Peet »

Usage:
Size: e.g. 5 R/S for "12345"
move: <from> enter <to> R/S ("from-value" must be higher than "to-value")
User ON, <A> automatic solution (only possible as long as no move has been made)

The last number from <from> is moved to the last position from <to>, e.g .:

1:123 2:4 3:5 - 3 ENTER 2 - 1:123 2:45 3:0
1:123 2:45 3:0 - 1 ENTER 3 - 1:12 2:45 3:3
1:12 2:45 3:3 - 2 ENTER 1 - 1:125 2:4 3:3
1:125 2:4 3:3 - 2 ENTER 3 - 1:125 2:0 3:34
1:125 2:0 3:34 - 1 ENTER 3 - 1:12 2:0 3:345
etc.

R00 n.a.
R01 1st place (start: e.g. 12345)
R02 2nd place
R03 3rd place
R04 <to>
R05 <from>
R06 <order> (copy of the start-tower e.g. 12345)
R07 attempts

more info: https://en.wikipedia.org/wiki/Tower_of_Hanoi

Code: Select all

LBL "HANOI"
FIX 0
CF 29
CLRG
"SIZE?"
PROMPT
STO 05 	
LBL 05
RCL 05	
RCL 04
10^X	
*	
ST+ 01  
1
ST+ 04	
DSE 05	
GTO 05 	
RCL 01
STO 06
GTO 02
LBL 01
AVIEW
STO 04
RDN
STO 05
4
X<=Y?
GTO 04
RCL 04
4
X<=Y?
GTO 04
RCL IND 05
10
/
FRC
RCL IND 04
10
/
FRC
X>Y?
GTO 00
ISG 07
X<>Y
RCL IND 05
10
/
INT
STO IND 05
LASTX
FRC
RCL IND 04
+
10
*
STO IND 04
LBL 02
CLA
ARCL 01
"|-*"
ARCL 02
"|-*"
ARCL 03
AVIEW
RCL 03
RCL 06
X=Y?
GTO 03
RTN 
GTO 01
LBL 00
"NO"
AVIEW
GTO 02
LBL 04
CLA
ARCL 07
"|- MOVES"
AVIEW
GTO 02
LBL 03
BEEP
CLA
ARCL 07  
"|- MOVES"
FIX 4
SF 29
PROMPT
LBL A		; Lösung
RCL 01
2
MOD
X=0?
GTO 10
1
3
XEQ 01
22
STO 13
GTO 11
LBL 10
1
2
XEQ 01
21
STO 13
LBL 11
XEQ 12
STO 04
RDN
STO 05
RCL IND 04
10
/
FRC
RCL IND 05
10
/
FRC
X>Y?
GTO 15
RCL 04
STO 05
LBL 15
RCL IND 05
2
MOD
X=0?
GTO 16
XEQ 20
X=0?
GTO 18
LBL 19
RCL 11
STO 04
GTO 30
LBL 18
RCL 12
STO 04
GTO 30
LBL 17
RCL IND 05
10
/
FRC
RCL IND 11
10
/
FRC
X>Y?
GTO 18
RCL IND 11
2
MOD
GTO IND 13
LBL 16
XEQ 20
X=0?
GTO 19
GTO 18
LBL 21
X=0?
GTO 18
GTO 19
LBL 22
X=0?
GTO 19
GTO 18
LBL 30
RCL 05
RCL 04
XEQ 01
GTO 11
LBL 20
RCL 05
STO 04
XEQ 12
STO 11
RDN
STO 12
RCL IND 05
10
/
FRC
RCL IND 12
10
/
FRC
X>Y?
GTO 19
RCL IND 12
X=0?
GTO 17
2
MOD
RTN
LBL 12
RCL 04
1
X=Y?
GTO 13
RCL 04
2
X=Y?
GTO 14
2
1
RTN
LBL 13
3
2
RTN
LBL 14
3
1
END
Attachments
19_HANOI.raw
(363 Bytes) Downloaded 7 times
My programmable calculators - former: CBM PR100, HP41CV, HP28S, HP11C - current: HP48G(+), HP35S, DM41X, DM42
Post Reply