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