Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Tower of Hanoi question
Message
De
23/06/2009 06:46:14
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01406816
Message ID:
01407738
Vues:
56
>Thanks Gregory - but as I said , my maths fail me - just thought someone could explain it in "plain english" - thanks anyway

A very simple strategy
while ( !GoalState )
	get batches
	if( batches.count = 1 )
		move the pile of disks from the peg containing the batch to the right peg
	else
		move first batch on top of second batch
UPDATE

This is the best stragegy - I believe

have tried the following config - 4 pegs - left to right = top to bottom
peg 1: { 2, 11, 13, 16, 17, 18 }
peg 2: { 3, 4, 5, 8, 15 }
peg 3: { 6, 9, 10, 20}
peg 4: { 1, 7, 12, 14, 19 }
The algorithm I have posted before chocked on this config, ie it took a long time to analyse (i have interruped it)

If I first combine the two top batches until there's only one batch left (ie all disks are on one peg), then it takes just over a second (1) To analyse and (2) to perform all the moves

Here's the output of the latter
> ()  >> :      1( 2 11 13 16 17 18 )   2( 3 4 5 8 15 ) 3( 6 9 10 20 )  4( 1 7 12 14 19 )

Time : 00:00:01.24  
Solved: 
Analyzed moves= 15, 
simple moves = 1899991, 
MaxOperationStackDepth = 39
intermediate steps
> ()  >> :      1( 2 11 13 16 17 18 )   2( 3 4 5 8 15 ) 3( 6 9 10 20 )  4( 1 7 12 14 19 )
Strategy Top 1> (1) 4 >> 1:     1( 1 2 11 13 16 17 18 ) 2( 3 4 5 8 15 ) 3( 6 9 10 20 )  4( 7 12 14 19 )
Strategy Top 2> (2) 1 >> 2:     1( 11 13 16 17 18 )     2( 1 2 3 4 5 8 15 )3( 6 9 10 20 )  4( 7 12 14 19 )
Strategy Top 5> (3) 2 >> 3:     1( 11 13 16 17 18 )     2( 8 15 )       3( 1 2 3 4 5 6 9 10 20 )        4( 7 12 14 19 )
Strategy Top 6> (4) 3 >> 4:     1( 11 13 16 17 18 )     2( 8 15 )       3( 9 1020 )    4( 1 2 3 4 5 6 7 12 14 19 )
Strategy Top 7> (5) 4 >> 2:     1( 11 13 16 17 18 )     2( 1 2 3 4 5 6 7 8 15 ) 3( 9 10 20 )    4( 12 14 19 )
Strategy Top 8> (6) 2 >> 3:     1( 11 13 16 17 18 )     2( 15 ) 3( 1 2 3 4 5 6 7 8 9 10 20 )    4( 12 14 19 )
Strategy Top 10> (7) 3 >> 1:    1( 1 2 3 4 5 6 7 8 9 10 11 13 16 17 18 )2( 15 ) 3( 20 ) 4( 12 14 19 )
Strategy Top 11> (8) 1 >> 4:    1( 13 16 17 18 )        2( 15 ) 3( 20 ) 4( 1 2 3 4 5 6 7 8 9 10 11 12 14 19 )
Strategy Top 12> (9) 4 >> 1:    1( 1 2 3 4 5 6 7 8 9 10 11 12 13 16 17 18 ) 2( 15 ) 3( 20 ) 4( 14 19 )
Strategy Top 13> (10) 1 >> 4:   1( 16 17 18 )   2( 15 ) 3( 20 ) 4( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 19 )
Strategy Top 14> (11) 4 >> 2:   1( 16 17 18 )   2( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 )        3( 20 ) 4( 19 )
Strategy Top 15> (12) 2 >> 1:   1( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18)       2( )    3( 20 ) 4( 19 )
Strategy Top 18> (13) 1 >> 4:   1( )    2( )    3( 20 ) 4( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 )
Strategy Top 19> (14) 4 >> 3:   1( )    2( )    3( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ) 4( )
Strategy Top 20> (15) 3 >> 4:   1( )    2( )    3( )    4( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 )
UPDATE 2

To calculate how many moves of one disk it is going to take to move a stack of n disks
			// update SimpleMoves
			SimpleMoves += Math.Pow(2.0, n) - 1.0;
Following config would require 1.37081612192351E+15 simple moves
var xx = new State(
		new List<uint> {  1, 7, 11, 12, 13, 15, 17, 21, 24, 28, 31, 38, 39, 48, 49, 50 },
		new List<uint> { 9, 14, 23, 27, 32, 35, 37, 45, 46 },
		new List<uint> { 2, 4, 10, 19, 26, 30, 34, 36, 42, 44, 47},
		new List<uint> { 3, 5, 6, 8, 16, 18, 20, 22, 25, 29, 33, 40, 41, 43}
	);
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform