Skip to content

Instantly share code, notes, and snippets.

@AlexAbraham1
Created January 4, 2015 00:12
Show Gist options
  • Save AlexAbraham1/ed31a98d4fa7a2c43597 to your computer and use it in GitHub Desktop.
Save AlexAbraham1/ed31a98d4fa7a2c43597 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class QueensBrute {
public static void main(String[] args) {
run();
}
public static void run()
{
int[] board = new int[8];
for (int i0 = 0; i0 < 8; i0++) {
for (int i1 = 0; i1 < 8; i1++) {
for (int i2 = 0; i2 < 8; i2++) {
for (int i3 = 0; i3 < 8; i3++) {
for (int i4 = 0; i4 < 8; i4++) {
for (int i5 = 0; i5 < 8; i5++) {
for (int i6 = 0; i6 < 8; i6++) {
for (int i7 = 0; i7 < 8; i7++) {
board[0] = i0;
board[1] = i1;
board[2] = i2;
board[3] = i3;
board[4] = i4;
board[5] = i5;
board[6] = i6;
board[7] = i7;
if (ok(board)) System.out.println(Arrays.toString(board));
}
}
}
}
}
}
}
}
}
public static boolean ok(int[] board)
{
for (int col = 0; col < 8; col++) {
for (int i = 0; i < col; i++) {
if (board[col] == board[i]) return false;
if (col - i == Math.abs(board[col] - board[i])) return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment