Tower of Hanoi on a HP-41CV

Posted by on January 10, 2025

It was much more fun to program this on my old HP calculator (not necessarily an optimal solution, but I wrote this around 40 years ago, my very first version…):

LBL "HANOI"
"N?"
PROMPT
STO 01
"A"
ASTO 02
"B"
ASTO 03
"C"
ASTO 04
10
STO 00
XEQ "INFIX"
STOP
LBL "INFIX"
1
RCL 01
X=Y?
GTO 01
XEQ "PUSH"
RCL 02
XEQ "PUSH"
RCL 03
XEQ "PUSH"
RCL 04
XEQ "PUSH"
1
ST- 01
RCL 04
X<> 03
STO 04
XEQ "INFIX"
XEQ "POP"
STO 04
XEQ "POP"
STO 03
XEQ "POP"
STO 02
XEQ "POP"
STO 01
LBL 01
CLA
ARCL 02
>"-"
ARCL 03
AVIEW
1
RCL 01
X=Y?
RTN
XEQ "PUSH"
RCL 02
XEQ "PUSH"
RCL 03
XEQ "PUSH"
RCL 04
XEQ "PUSH"
1
ST- 01
RCL 04
X<> 02
STO 04
XEQ "INFIX"
XEQ "POP"
STO 04
XEQ "POP"
STO 03
XEQ "POP"
STO 02
XEQ "POP"
STO 01
END
LBL "PUSH"
STO IND 00
1
ST+ 00
RTN
LBL "POP"
1
ST- 00
RCL IND 00
END

I called the pegs “A”, “B” and “C” this time:

Comments are closed.