O'Reilly logo

Mastering JavaScript Functional Programming by Federico Kereki

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Eight Queens puzzle

The Eight Queens puzzle was invented in the XIX Century and requires placing eight chess queens on a standard chessboard. The special condition is that no queen may attack another -- implying that no pair of queens may share a row, column, or diagonal line. The puzzle may ask for any solution or, as we shall do it, for the total number of distinct solutions.

The puzzle may also be generalized to n queens, by working on an nxn square board. It is known that there are solutions for all values of n, except n=2 (pretty simple to see why: after placing one queen, all of the board is threatened) and n=3 (if you place a queen on the center, all of the board is threatened, and if you place a queen on a side, only two squares ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required