View Single Post
  #16  
Old 06-15-2008, 04:49 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Not sure if I entirely understood the task, but I suppose this should work?

PHP Code:
function onCreated() {
  
temp.students_incompatible = {{1,2},{3,49}};
  
temp.students_total = new[400];
  
temp.house_list = {};
  
  while (
temp.house_list.size() < 100) {
    
temp.i = 0;
    while (
temp.students_total[temp.i] == 1)
      
temp.i ++;
    
temp.students_total[temp.i] = 1;
    
temp.j = temp.i;
    
    
temp.go = false;
    while (
temp.students_total[temp.j] == 1 || !temp.go) {
      if ((@ {
temp.i + 1,temp.j + 1}) in temp.students_incompatible) {
        
temp.go = false;
        
temp.j ++;
      }
      else if ((@ {
temp.j + 1,temp.i + 1}) in temp.students_incompatible) {
        
temp.go = false;
        
temp.j ++;
      }
      else if (
temp.students_total[temp.j] == 1)
        
temp.j ++;
      else
        
temp.go = true;
    }
    
temp.students_total[temp.j] = 1;
    
temp.house_list.add({temp.i + 1,temp.j + 1});
  }
  echo(
temp.house_list);
} 
Time: 0.008579015
__________________

Last edited by Dan; 06-15-2008 at 05:07 PM.. Reason: Added time.
Reply With Quote