[27c31b]: examples / towers_of_hanoi / README  Maximize  Restore  History

Download this file

20 lines (14 with data), 696 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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(num_disks)

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

Sign up for the SourceForge newsletter:





No, thanks