
Posted by Moby Dick
![]()
on 7/8/2009, 9:54 pm, in reply to "Re: A Major Challenge for True Puzzlers"
My program completes almost instantly - with 2048 calls to the find() function having been made. However - I have not proven that it is bug free:
public struct fixt
{
public int t1 { get; set; }
public int t2 { get; set; }
public int play { get; set; }
}
public int returns;
public void find(List
{
for (int i = 0; i <= 1; i++)
{
fixt gm = games[level];
gm.play = i;
games[level] = gm;
int[] sums = new int[14];
foreach (fixt g in games)
{
if (g.play == 1)
{
sums[g.t1 - 1]++;
sums[g.t2 - 1]++;
}
}
bool possible = true;
for (int j = 0; j <= 13; j++)
{
if (sums[j] > 4) //max 4 opponents for each team
{
possible = false;
}
}
if (possible)
{
if (level < games.Count - 1)
{
find(games, level + 1);
}
else //check opponents in common condition
{
int[,] checker = new int[14, 14];
for (int j = 0; j <= 13; j++)
{
checker[j, j] = 1;
}
foreach (fixt g1 in games)
{
if (g1.play == 1)
{
checker[g1.t1 - 1, g1.t2 - 1]++;
foreach (fixt g2 in games)
{
if (g2.play == 1)
{
if (!((g1.t1 == g2.t1) && (g1.t2 == g2.t2)))
{
if (g1.t1 == g2.t1)
{
checker[g1.t2 - 1, g2.t2 - 1]++;
checker[g2.t2 - 1, g1.t2 - 1]++;
}
if (g1.t1 == g2.t2)
{
checker[g1.t2 - 1, g2.t1 - 1]++;
checker[g2.t1 - 1, g1.t2 - 1]++;
}
if (g1.t2 == g2.t1)
{
checker[g1.t1 - 1, g2.t2 - 1]++;
checker[g2.t2 - 1, g1.t1 - 1]++;
}
if (g1.t2 == g2.t2)
{
checker[g1.t1 - 1, g2.t1 - 1]++;
checker[g2.t1 - 1, g1.t1 - 1]++;
}
}
}
}
}
}
bool poss = true;
for (int x = 0; x <= 13; x++)
{
for (int y = 0; y <= 13; y++)
{
if (checker[x, y] == 0)
{
poss = false;
}
}
}
if (poss)
{
MessageBox.Show("Solution found");
}
else
{
returns++;
return;
}
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
List
for (int t1 = 1; t1 <= 13; t1++)
{
for (int t2 = t1 + 1; t2 <= 14; t2++)
{
if (t1 != t2)
{
fixt game = new fixt();
game.t1 = t1;
game.t2 = t2;
game.play = 0;
games.Add(game);
}
}
}
find(games, 0);
MessageBox.Show(returns.ToString() + " returns from call");
button1.Enabled = true;
}
}
Note: some items (e.g. list parameters) not showing due to forum's lack of a [code] option.


Message Thread:
![]()
« Back to thread