06-14-2008, 07:50 PM
|
penguin.
|
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
|
|
Quote:
Originally Posted by Programmer
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
|
Once again, this failed to perform the task.
Again, let's discuss what we ought to be doing to solve this problem. This is a very difficult problem to solve (HRs idea, don't blame me). |
__________________
Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
|
|
|