Code:
int y ( 1 );
int x = 2^discs;
for ( int i = 1 ; i < x ; i++ )
{
if ( i & 1 )
{
if ( y == 3 )
{
gold_discs--;
copper_discs++;
copper_rod [ copper_discs ] = 1;
y = 2;
}
else
{
if ( y == 1 )
{
copper_discs--;
silver_discs++;
silver_rod [ silver_discs ] = 1;
y = 3;
}
else
{
silver_discs--;
gold_discs++;
gold_rod [ gold_discs ] = 1;
y = 1;
}
}
}
else
{
make only legal move left;
}
}
I think I've got the algorithm in my head, is this about right?
On odd moves you set the lowest disc to A -> B -> C -> A -> .. and on the even moves you make the only legal move possible. But how could I check for that?