Tree [f16399] default / examples / towers_of_hanoi /
 History

Read Only access


File Date Author Commit
 README.txt 2009-11-03 mtnyogi mtnyogi [bd3505] Renamed all README files to README.txt
 __init__.py 2008-12-29 mtnyogi mtnyogi [5d0d34] - Changed second param to engine.__init__ to be...
 test.py 2010-02-25 mtnyogi mtnyogi [f16399] Took out %var syntax from goal.compile.
 towers2.krb 2008-08-29 mtnyogi mtnyogi [0ee160] Finished with the documentation! (Well, almost...
 towers_of_hanoi.krb 2008-08-29 mtnyogi mtnyogi [0ee160] Finished with the documentation! (Well, almost...
 towers_of_hanoi.tst 2009-10-24 mtnyogi mtnyogi [3e0ae6] Cleaning up test scripts.

Read Me

This solves the Towers of Hanoi puzzle through brute force but with the
restrictions of never repeating a board position and never moving the
same disc twice in a row.  Running this, you'll see the following pattern:

    1 disc has 1 solution
    2 discs has 2 solutions
    3 discs has 12 solutions
    4 discs has 1872 solutions

Sure enough, if the number of solutions for n discs is N, the number of
solutions for n+1 discs is: N**3 + N**2.  (I leave the explanation of why this
is so to the reader! :-)

This would mean that 5 discs has 6,563,711,232 solutions, but I haven't run
this to verify the answer...

    >>> from examples.towers_of_hanoi import test
    >>> test.test(2)    # test takes the number of disks as an argument
    got 1: ((0, 1), (0, 2), (1, 2))
    got 2: ((0, 2), (0, 1), (2, 0), (1, 2), (0, 2))

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks