// How to run: // // $ cargo run -q examples/nqueen.c > tmp-nqueen.s // $ gcc -static -o tmp-nqueen tmp-nqueen.s // $ ./tmp-nqueen int print_board(int *board) { for (int i=0; i<10; i=i+1) { for (int j=0; j<10; j=j+1) { if (board[i*10+j]) { printf("Q "); } else { printf(". "); } } printf("\n"); } printf("\n\n"); return 0; } int conflict(int *board, int row, int col) { for (int i=0; i 9) { print_board(board); return 0; } for (int i=0; i<10; i=i+1) { if (conflict(board, row, i)) { } else { board[row * 10 + i] = 1; solve(board, row + 1); board[row * 10 + i] = 0; } } return 0; } int main() { int board[100]; for (int i=0 ; i<100 ; i=i+1) board[i] = 0; solve(board, 0); return 0; }