Created
February 12, 2014 17:11
-
-
Save VienosNotes/8959970 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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