View Single Post
  #15  
Old 06-14-2008, 07:44 AM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
Quote:
Originally Posted by Tolnaftate2004 View Post
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
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote