HOME | DD

Fresh-Grass — N-Queens on NxM board

Published: 2010-08-22 12:35:35 +0000 UTC; Views: 629; Favourites: 0; Downloads: 0
Redirect to original
Description 8 queens is common chess problem, the task is to place 8 queens on standard 8x8 chessboard without queens attacking each other. This program accepts any size of the board (NxM).
Rather than using a 2D array (matrix), all necessary data (x-coordinates of attacked squares) is stored in 1D array.
The values in the array are modified in each row:
elements at n*3 are decremented by 1
element at n*3+1 are left unchanged
elements at n*3+2 are incremented by 1

The code in 3 different languages:
C++ [link]
C# [link]
Java [link]
Related content
Comments: 0