Post Reply 
Weakest calculator/pocket computer that can do Tower of Hanoi?
08-14-2018, 12:47 AM (This post was last modified: 09-10-2018 04:09 PM by Thomas Klemm.)
Post: #25
RE: Weakest calculator/pocket computer that can do Tower of Hanoi?
(08-13-2018 11:47 AM)Thomas Klemm Wrote:  There are 12 lines left that could be used for a loop or a fancy display or what not.

Meanwhile I was able to remove another step.
This allows to output a single line in an infinite loop:
Code:
01 1           ; 1
02 STO 0       ; n=1
03▸RCL 0       ; k=n
04 1           ; 1 k
05 STO 1       ; a=1 k
06 STO 2       ; m=1 k
07▸R↓          ; k
08 2           ; 2 k
09 ÷           ; k/2
10 FRAC        ; {k/2}
11 x≠0         ; k % 2 ≠ 0 ?
12 GTO 20      ; done
13 LASTx       ; k'=k/2
14 2           ; 2 k'
15 STO × 1     ; a'=2a
16 R↓          ; k'
17 1           ; 1 k'
18 STO + 2     ; m'=m+1
19 GTO 07      ; while
20▸RCL 0       ; n
21 RCL 1       ; a n
22 +           ; n+a
23 3           ; modulo 3
24 ÷           ;
25 FRAC        ;
26 4           ;
27 ×           ;
28 INT         ; to=(n+a)%3
29 1           ;
30 0           ; 10 to
31 ÷           ; 0.to
32 RCL 0       ; n 0.to
33 RCL 1       ; a n 0.to
34 -           ; n-a 0.to
35 3           ; modulo 3
36 ÷           ;
37 FRAC        ;
38 4           ;
39 ×           ;
40 INT         ; from=(n-a)%3 0.to
41 +           ; from.to
42 1           ; 1
43 STO + 0     ; n=n+1
44 10^x        ; 10 from.to
45 ÷           ; 0.from-to
46 RCL 2       ; disk 0.from-to
47 +           ; disk.from-to
48 R/S         ; show move
49 GTO 03      ; next n

Make sure to have the display set to FIX 2 which is the default after starting up the calculator.

Example:

GTO 00
R/S
X: 1.02
R/S
X: 2.01
R/S
X: 1.21
R/S
X: 3.02
R/S
X: 1.10



Thus:
  1. move disk 1 from peg 0 to peg 2
  2. move disk 2 from peg 0 to peg 1
  3. move disk 1 from peg 2 to peg 1
  4. move disk 3 from peg 0 to peg 2
  5. move disk 1 from peg 1 to peg 0



Cheers
Thomas
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? - Thomas Klemm - 08-14-2018 12:47 AM



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