Logic for Fun: Third Demo

Eight Queens Problem

Find all the ways to place eight queens on an ordinary chessboard so that no queen attacks any other queen.

Two queens attack each other if they are on the same rank (horizontal row) or the same file (vertical column) or the same diagonal.

For extra credit, design a neat way to make the solver print the solutions in a pretty format.


Click on PROBLEM ENCODING below to see what this looks like in logical notation. Notice that the queens problem itself only requires one clause: all the rest is for pretty-printing, which of course is theoretically redundant.

Clicking on SOLUTION on the encoding page will give you the answer to the problem, exactly as the solver prints it.

Copyright © 2001, 2006 by The Australian National University