Weakest calculator/pocket computer that can do Tower of Hanoi?
|
08-13-2018, 11:47 AM
(This post was last modified: 09-10-2018 04:08 PM by Thomas Klemm.)
Post: #20
|
|||
|
|||
RE: Weakest calculator/pocket computer that can do Tower of Hanoi?
(08-13-2018 07:03 AM)Paul Dale Wrote: Regardless, I'm not yet ready to admit that a complete solution is totally impossible (I'm close but not quite yet). Here's a program for the HP-25: Code: 01 STO 0 ; k=n For a move \(n\) it returns: Z: to Y: from X: disk Example: 12 R/S Z: 1 Y: 2 X: 3 Thus move disk 3 from peg 2 to peg 1. It's the translation of the following Python program: Code: def hanoi(n): This is the list for all moves for 5 disks: Code: >>> for n in range(1, 2**5): There are 12 lines left that could be used for a loop or a fancy display or what not. Cheers Thomas Addendum: I've used from Binary solution of Tower of Hanoi: Quote:Another formulation is from peg (m - (m & -m)) % 3 to peg (m + (m & -m)) % 3 And then from A006519: Quote:Highest power of 2 dividing n. But I went the other way round: first I've generated the from and to sequences and looked them up in OEIS. Only when I figured out the formulas I found them in Wikipedia. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)