Recursive Tower of Hanoi

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
michel.lample
Posts: 20
Joined: Wed May 03, 2017 5:09 pm

Recursive Tower of Hanoi

Post by michel.lample »

Hello all
I'm trying to test the local variables of the DM42 (LSTO) with the Tower of Hanoi alogrithm.... 39 program steps! Wouaou, that reminds me my old HP33E.

But I have a little question: thanks to the swissmicros encoder/decoder because... hmm, I've never been able to find LSTO in the PGM.FNC catalog.
I wonder where it is...

Regards
Michel

The Hanoi towers are numeroted 1,2,3
The number of disk can be any positive integer.
To run the program, the stack must contain : x=Nr of disks, y=From tower, z=Intermediate Tower, t=Destination tower
By eg, to move 5 disks from 1 to 3, press: 3 Enter 2 Enter 1 Enter 5 XEQ "HANOI"

Code: Select all

00 { 172-Byte Prgm }
01▸LBL "HANOI" (x,y,z,t= Nb, From, Interm, To)
02 LSTO "N"
03 R↓
04 LSTO "From"
05 R↓
06 LSTO "Inter"
07 R↓
08 LSTO "To"
09 RCL "N"
10 1
11 X=Y?
12 GTO F
13 1
14 STO- "N"
15 RCL "Inter"
16 RCL "To"
17 RCL "From"
18 RCL "N"
19 XEQ "HANOI"
20 "Move disk from "
21 ARCL "From"
22 ├" to "
23 ARCL "To"
24 AVIEW
25 STOP
26 RCL "To"
27 RCL "From"
28 RCL "Inter"
29 RCL "N"
30 XEQ "HANOI"
31 RTN
32▸LBL F
33 "Move disk from "
34 ARCL "From"
35 ├" to "
36 ARCL "To"
37 AVIEW
38 STOP
39 RTN
Last edited by michel.lample on Wed Jun 17, 2020 6:57 pm, edited 1 time in total.
grsbanks
Posts: 1122
Joined: Tue Apr 25, 2017 11:23 am
Location: Preston, Lancs, UK
Contact:

Re: Revursive Tower of Hanoi

Post by grsbanks »

michel.lample wrote:
Wed Jun 17, 2020 5:48 pm
But I have a little question: thanks to the swissmicros encoder/decoder because... hmm, I've never been able to find LSTO in the PGM.FNC catalog.
I wonder where it is...
[CATALOG] FCN [▲] [▲]
There are only 10 kinds of people in the world: those who understand binary and those who do not.
michel.lample
Posts: 20
Joined: Wed May 03, 2017 5:09 pm

Re: Revursive Tower of Hanoi

Post by michel.lample »

grsbanks wrote:
Wed Jun 17, 2020 6:00 pm
[CATALOG] FCN [▲] [▲]
Thank you!
Post Reply