This is an expanded version of the classic '8-Queens' problem to generate a solution for any passed integer. But really, don't try it with numbers higher than 17. For your CPU's sake.
Note: Some passed integers will have no possible solution. Try in the range 4 <-> 17.