Post Reply 
Weakest calculator/pocket computer that can do Tower of Hanoi?
08-12-2018, 09:35 AM (This post was last modified: 08-12-2018 09:48 AM by Thomas Klemm.)
Post: #10
RE: Weakest calculator/pocket computer that can do Tower of Hanoi?
(08-12-2018 07:46 AM)Thomas Okken Wrote:  That program always returns 1, for any input.

That's weird. Are you sure that you've entered these lines?
Code:
13 1
14 +

Quote:Even if it did do what you say it should do, it would still be only a partial solution, because all it would tell you is which disc should be moved at any given step. The reason why my (second) program is so much longer is because it works out from from which to which position the disc is moved.

It depends on how a solution is specified. You could give the sequence A001511 to someone and without understanding the rules it would be possible to play the game. You'd have to know how to move odd and even disk numbers differently but you could colour the disks accordingly which would give them a nice touch.

If you desperately need to know the positions they could be calculated from \(n\) and \(a(n)\):

Here's a Python program:
Code:
def hanoi(n):
    k, a = n, 1
    while not k % 2:
        k /= 2
        a += 1
    p = n / 2**a
    q, r = (p % 3, (p+1) % 3) if a % 2 else ((-p) % 3, (-p-1) % 3)
    return a, q, r

for i in range(1, 2**5):
    print hanoi(i)

And this is the generated output:
Code:
(disk, from, to)
(1, 0, 1)
(2, 0, 2)
(1, 1, 2)
(3, 0, 1)
(1, 2, 0)
(2, 2, 1)
(1, 0, 1)
(4, 0, 2)
(1, 1, 2)
(2, 1, 0)
(1, 2, 0)
(3, 1, 2)
(1, 0, 1)
(2, 0, 2)
(1, 1, 2)
(5, 0, 1)
(1, 2, 0)
(2, 2, 1)
(1, 0, 1)
(3, 2, 0)
(1, 1, 2)
(2, 1, 0)
(1, 2, 0)
(4, 2, 1)
(1, 0, 1)
(2, 0, 2)
(1, 1, 2)
(3, 0, 1)
(1, 2, 0)
(2, 2, 1)
(1, 0, 1)

Is that what you want?

Not sure if we can squeeze that into the 49 lines of a HP-25 though.

(08-12-2018 01:46 AM)Thomas Okken Wrote:  Not having MOD really hurts. Smile

Agreed.

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-12-2018 09:35 AM



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