In implementing the 8 queens puzzle I decided to crate a Javascript interface that allows one to try and place queens on the chessboard of arbitrary size.

By clicking on a cell a queen is placed or removed. Highlighted cells show the threats created by placing a queen at that location. Yellow cells show that the highlighted area poses a threat. Red cells show the board is in conflict. A fully green board shows a solution.

One can generally find solutions to the smaller boards pretty quickly. The larger boards get very complected but also have more possible solutions. The solve button will use the method of permutations to try and find a random solution. For the larger boards it may not find a solution and will time out after 30 seconds. However, trying again will eventually produce a result and sometimes quite fast. It really depends on how the board was shuffled. The total number of solutions to test for any board is *n!* where *n* is the number of rows/columns.

Rows/Columns | Total Permutations |
---|---|

4 | 24 |

5 | 120 |

6 | 720 |

7 | 5,040 |

8 | 40,320 |

9 | 362,880 |

10 | 3,628,800 |

11 | 39,916,800 |

12 | 479,001,600 |

13 | 6,227,020,800 |

14 | 87,178,291,200 |

15 | 1,307,674,368,000 |

16 | 20,922,789,888,000 |

17 | 355,687,428,096,000 |

18 | 6,402,373,705,728,000 |

19 | 121,645,100,408,832,000 |

20 | 2,432,902,008,176,640,000 |

That last number is 2.4 quintillion. For comparison a computer counting at 4 billion counts/second (4 GHz) would take 19 years just to count that high.

Download a zip file of the project: nQueens_v1.0.zip. SHA256: a0de13bc06dd9a2cb8cde3b535939825946b07e8f8164b51fb6f2af89f0c7f11.