Skip to content

Instantly share code, notes, and snippets.

@VienosNotes
Created February 12, 2014 17:11
Show Gist options
  • Select an option

  • Save VienosNotes/8959970 to your computer and use it in GitHub Desktop.

Select an option

Save VienosNotes/8959970 to your computer and use it in GitHub Desktop.
var success;
var board[8];
var yokoArray[8];
var leftUpper[88];
var rightUpper[88];
main() {
var max, state;
max = 8 * 8 * 8 * 8 * 8 * 8 * 8 * 8;
state = 0;
success = 0;
while (state < max) {
check(state);
state = state + 1;
}
println("%d", success);
return;
}
check(getState) {
var cur, i, yoko, tate;
cur = getState;
i = 0;
while(i < 88) {
leftUpper[i] = 0;
rightUpper[i] = 0;
i = i + 1;
}
i = 0;
while(i < 8) {
board[i] = cur % 8;
cur = cur / 8;
yokoArray[i] = 0;
i = i + 1;
}
i = 0;
while(i < 8) {
if (yokoArray[board[i]]) {
return;
} else {
yokoArray[board[i]] = 1;
}
i = i + 1;
}
i = 0;
while(i < 8) {
yoko = i;
tate = board[i];
while (yoko * tate) {
yoko = yoko - 1;
tate = tate - 1;
}
if (leftUpper[yoko * 10 + tate]) {
return;
} else {
leftUpper[yoko * 10 + tate] = 1;
}
i = i + 1;
}
i = 0;
while(i < 8) {
yoko = i;
tate = 7 - board[i];
while (yoko * tate) {
yoko = yoko - 1;
tate = tate - 1;
}
if (rightUpper[yoko * 10 + tate]) {
return;
} else {
rightUpper[yoko * 10 + tate] = 1;
}
i = i + 1;
}
success = success + 1;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment