Solutions to the 8-Queens Problem

This problem is to place 8 queens on the chess board so that they do not check each other. This problem is probably as old as the chess game itself, and thus its origin is not known, but it is known that Gauss studied this problem. If we want to find a single solution, it is not difficult as shown below. If we want to find all possible solutions, the problem is difficult and the backtrack method is the only known method. For 8-queen, we have 92 solutions. If we exclude symmetry, there are 12 solutions.

Consider the general case of the n-Queens Problem

If n is a prime number, a solution is easily found by drawing a straight line in the (n, n) finite plane. Since no two straight lines can intersect at two points, a straight line y=ax+b where a is not equal to 1 or -1 can give a solution. Coordinates start from 0.

The ratio of analytical solutions for the total solutions for
some small p is as follows:

p=5, 10/10, 100%

p=7, 28/40, 70%

p=11, 99/2680, 4%

For composite numbers n=pq, we can make a direct product of the p-queen and
q-queen problems. That is, each queen position of the p-queen problem is regarded
as a solution of the q-queen problem. We can change the roles of p and q.
Thus for 35=5*7, we can generate 10*(40)^5 + 40*(10)^7 solutions.

To generate one solution for a general n, let the plane coordinated
by i=0, ..., n-1 and j=0, ..., n-1.