Post Reply 
Weakest calculator/pocket computer that can do Tower of Hanoi?
08-13-2018, 01:07 PM
Post: #21
RE: Weakest calculator/pocket computer that can do Tower of Hanoi?
Very nice code, Thomas. I'll have to see if I can use any of that algorithm to improve my clumsy Casio fx-7000g version. Smile

(N.B.: I've used the more standard ^ symbol for the x^y key, and (10^) to represent the small "10" that corresponds to 10^x.)

Prog 0
Code:
Mcl
Range 1,95,0,1,64,0
"N"?→N
2Frac (N÷2→O
2^N-1→M
9→P:9→Q:9→R
N→U:9→V:18→W
U→I
Lbl 0
N-I+1→D
Prog 2
Dsz I:Goto 0
1→B
Prog 3
Lbl 1
B→F
B+1+O→G
G>3⇒G-3→G
B+2-O→B
B>3⇒B-3→B
T[F→I:Prog 1
D→C
T[G→I:Prog 1
C<D⇒Goto 2
D→C:F→S:G→F:S→G
Lbl 2
0→D:T[F→I:Prog 2
Dsz T[F]:Ans
Isz T[G]
C→D:T[G→I:Prog 2
Prog 3
Dsz M
Goto 1

Prog 1 - This is a register-packing "get" routine.
Code:
P[Int(I÷9→Z
9Frac (I÷9→E
10Frac (Int (Z÷(10^)E)÷10→D

Prog 2 - And this is the corresponding "put" routine.
Code:
D→H
Prog 1
Z-D(10^)E+H(10^)E→P[Int (I÷9)]

Prog 3 - Display routine. There's no way to selectively erase parts of the screen, so the entire screen must be cleared and redrawn after each move.
Code:
Cls
-14→J
0→I
Lbl 1
J+16→J
0→K
Lbl 2
Prog 1
D=0⇒Goto 3
K+2→K
Plot J+8-D,K
Plot J+7+D,K
Line
Lbl 3
Isz I
0≠Frac (I÷9⇒Goto 2
I<27⇒Goto 1
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Weakest calculator/pocket computer that can do Tower of Hanoi? - Dave Britten - 08-13-2018 01:07 PM



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