Quote:
Originally Posted by Tolnaftate2004
This does not test if switching 2 people forms compatibility...
|
Picky, Picky.
PHP Code:
function onCreated()
{
this.start = timevar2;
this.incompatability = {
{102, 284},
{392, 126},
{1, 2},
{3, 4},
{5, 6},
{7, 8}
};
this.studentsSelected.clear();
this.studentGroups.clear();
numStudentsSelected = 0;
// Select students at random
for (i = 0; i < 100; i++)
{
f = int(random(0, 400));
if (this.studentsSelected.index(f) == -1)
{
this.studentsSelected.add(f);
} else
{
i--; continue;
}
}
// Group them
for (i = 0; i < this.studentsSelected.size(); i += 2)
{
this.studentGroups.add({this.studentsSelected[i], this.studentsSelected[i+1]});
}
// Remove incompatabilities
for (i = 0; i < 50; i++)
{
sGroup = this.studentGroups[i];
for (a = 0; a < this.incompatability.size(); a++)
{
if ((sGroup[0] == this.incompatability[a][0] || sGroup[0] == this.incompatability[a][1]) && (sGroup[1] == this.incompatability[a][0] || sGroup[1] == this.incompatability[a][1]))
{
echo("INCOMPATABILITY: " @ sGroup);
// we've found an incompatability, so lets flip this student with the next group
sGroup2 = this.studentGroups[i+1];
sGroup[0] = sGroup2[0];
this.studentGroups[i] = sGroup;
this.studentGroups[i+1] = sGroup2;
i--;
continue;
}
}
}
this.end = timevar2;
echo(this.end - this.start);
for (i = 0; i < 50; i++)
{
echo("Group " @ (i+1) @ ": {" @ this.studentGroups[i][0] @ ", " @ this.studentGroups[i][1] @ "}");
}
}
Time: 0.001927852