The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two queens attack each other. For example, following are a solutions for 4 Queen problem.
These are known solutions for the NQueen problem
We need to generate and store most solutions in < 10 minutes
Generating from 8x8 to 13x13 N size we have the next results:
![]()
Generating from 8x8 to 15x15 N size we have the next results:

The problem here is that we have 2,279,184 solutions that we want to store in a database. With some optimizations with SQLAlchemy we can have the next results:
We can see the count per record in the datase with the next query:
We can see there are not solutions listed for dimension 2x2 or 3x3, that's because are not known solutions as we can see on the follow query:
- Martin Richards https://www.cl.cam.ac.uk/~mr10/backtrk.pdf
- Andrés Muñoz https://www.youtube.com/watch?v=XQYGwKiqV3Y
We can see the stored solutions in http://localhost:1001/
To run the project we need Docker installed in your system.
docker-compose up
To create the database run the script
docker-compose run nqueens flask initdb
To run the tests we have some scripts:
- This is to check from 1x1 to 12x12
docker-compose run nqueens python -m pytest app/tests/tests.pyhelped me with some refactors - This is to run from 8x8 to 15x15
docker-compose run nqueens python -m pytest app/tests/tests_solutions_not_saving.py - This is to run from 8x8 to 15x15 and save it into database
docker-compose run nqueens python -m pytest app/tests/tests_solutions.py - This is to run from 8x8 to 15x15 from database
docker-compose run nqueens python -m pytest app/tests/tests_solutions_stored.py
Tests are automated thanks to github actions
Here are automated test runned in this project.






