(42) Tower of Hanoi graphical version
|
07-07-2021, 10:54 PM
Post: #1
|
|||
|
|||
(42) Tower of Hanoi graphical version
I didn’t see a program that actually displays the Tower of Hanoi discs, so I wrote one for the 42s for 5 discs. To run this Tower of Hanoi program, XEQ TH
When the program pauses, type a 2 digit number (between 1 and 3) with the first digit (tens place) being the from pile and the second digit (ones place) being the to pile. Then, press R/S. Then repeat, until the puzzle is solved. There are no checks to make sure the moves are valid or if the tower has been completely moved. Registers 00 to 02 store pile information. The first pile, in register 00, is 97531. To move a disc from one pile to another, we: Divide by 10 for the from pile. Add the fraction part to the to pile. Multiply the to pile by 10. Store the integer part of the from pile to the from pile. TH1 processes the move command. Register 4 is the from pile and register 5 is the to pile. TH5 displays the 3 piles. Register 13 holds the pile number to display. TH3 sets things up to display a pile. TH4 is the loop to setup to display each disc. Register 10 is the X coordinate of the disc. Register 11 is the Y coordinate of the disc. Register 7 is ISG counter. TH2 actually displays the disc. Using the AGRAPH command, I found that the program runs at a usable speed on a HP 42s (compared to using the PIXEL command). Code:
|
|||
07-09-2021, 12:27 PM
Post: #2
|
|||
|
|||
RE: (42) Tower of Hanoi graphical version
For the 'eclectic' minded: The Tower of Hanoi – Myths and Maths 2e, Hinz-Klavžar-Petr, Birkhäuser, ISBN 978-3-319-73779-9 (e-book), 458 pgs.
[attachment=9630] BEST! SlideRule |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)