I recently wrote some code on the flight from Boston to CA to get at least 1 solution to the N Queens problem.
This is a recursive backtracking based algorithm – which I have solved using iterative backtracking.
The code is attached and written in python.
This code may not be super optimized but is small enough and correct.
We can add a wrapper on top of this code easily to output all the possible solutions of the N Queens problem
This program takes 1 parameter – the Size of the Grid. It is assumed that it is a Square Grid
It outputs the possible coordinates to place the N Queens
The grid Index starts from 1
Simple way to run the program using Python interpreter
python 8QueensProblem.py <N>
Where <N> is the Grid Size