Function Repository Resource:

NQueenSolution

Source Notebook

Give the solution to the n-queen problem

Contributed by: Aster Ctor

ResourceFunction["NQueenSolution"][n]

gives the solution to the n-queen problem.

Details and Options

The n-queens problem consists of putting n queens on an n×n chessboard such that no two queens attack one another.
The solution is a list of numbers of length n, which indicates the position within each column where the queen should be placed.
The option Method supports the following types:
"Unique"show only one solution
"All"show all solutions
"CountAll"give the number of all solutions

Examples

Basic Examples (2) 

Get one of the solutions to the 8-queens problem:

In[1]:=
ResourceFunction["NQueenSolution"][8]
Out[1]=

Visualize this solution:

In[2]:=
gridView[l_List] := Block[
   {n = Length@l, array},
   array = SparseArray[MapIndexed[{#, First@#2} -> "Q" &, l], {n, n}, "."];
   Grid[Normal@array, Frame -> All]
   ];
gridView@ResourceFunction["NQueenSolution"][8]
Out[3]=

Scope (3) 

Get all the solutions to the 8-queens problem:

In[4]:=
sols = ResourceFunction["NQueenSolution"][8, Method -> "All"];
sols // Short
Out[5]=

Count the number of solutions:

In[6]:=
sols // Length
Out[6]=

Compute the number of solutions directly:

In[7]:=
ResourceFunction["NQueenSolution"][8, Method -> "CountAll"]
Out[7]=

Neat Examples (2) 

Display the solution with a beautiful chessboard:

In[8]:=
prettyView[l_List] := Block[
   	{n = Length@l, array, dark, light, queen, range, drawBoard},
   range = Boole@NestList[RotateLeft, Table[EvenQ[i], {i, Range@n}], n - 1];
   array = SparseArray[MapIndexed[{#, First@#2} -> "Q" &, l], {n, n}, "."];
   {dark, light} = {RGBColor[0.8196, 0.5451, 0.2784], RGBColor[1, 0.8078, 0.6196]};
   queen = \!\(\*
GraphicsBox[
TagBox[RasterBox[CompressedData["
1:eJztnQn4TdX6x1dUkijJmKKBSClTA6LS6F5CJaLBWKLwI0Uobq6IBkOp220g
TVxxKxl7eqJUolKJIup/K41ImRr2f3/XOfv3bMdew1577bPP73fez/O89+n6
nbPXu9da7z77fde73nVc9/4depdgjA06xP2fDt1uO6+goNvQy49w/8+Vtwzq
c8MtvXpeesvgXjf0Kjire0n3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QRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAE
QRAEQRAEQRAEQRAx8v9wVWR0
"], {{0, 200}, {200, 0}}, {0, 255},
ColorFunction->RGBColor],
BoxForm`ImageTag["Byte", ColorSpace -> "RGB", Interleaving -> True],
Selectable->False],
DefaultBaseStyle->"ImageGraphics",
ImageSizeRaw->{200, 200},
PlotRange->{{0, 200}, {0, 200}}]\) ;
   drawBoard[board_] := ArrayPlot[
     range,
     ColorRules -> {0 -> light, 1 -> dark}, Frame -> False,
     Epilog -> (Inset[queen, # - 1, # - 1, 1] & /@ Position[board, "Q"])
     ];
   drawBoard@Normal@array
   ];

View the solution:

In[9]:=
prettyView@ResourceFunction["NQueenSolution"][8]
Out[9]=

Publisher

Aster Ctor (MoeNet)

Version History

  • 1.0.0 – 27 December 2019

Related Resources

License Information