N-queens problem: Difference between revisions
Content added Content deleted
m (→Python: Niklaus Wirth algorithm: Removed redundant (duplicate) example.) |
m (→Python: Niklaus Wirth algorithm: Revised one sentence) |
||
Line 12,841: | Line 12,841: | ||
for solution in queens(8, 0, [], [], []): |
for solution in queens(8, 0, [], [], []): |
||
print(solution)</syntaxhighlight> |
print(solution)</syntaxhighlight> |
||
The algorithm can be easily improved by using sets instead of lists and avoiding time- and space-consuming implicit copy operations. On a regular 8x8 board only 5,508 possible queen positions are examined. |
The algorithm can be easily improved by using sets instead of lists and by avoiding the time- and space-consuming implicit copy operations during recursion. On a regular 8x8 board only 5,508 possible queen positions are examined. |
||
<syntaxhighlight lang="python">def queens(n: int): |
<syntaxhighlight lang="python">def queens(n: int): |
||