N-queens minimum and knights and bishops: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Improvement for knights.) |
(→{{header|Wren}}: Incorporated latest Go improvement.) |
||
Line 1,629: | Line 1,629: | ||
This was originally based on the Java code [https://www.geeksforgeeks.org/minimum-queens-required-to-cover-all-the-squares-of-a-chess-board/ here] which uses a backtracking algorithm and which I extended to deal with bishops and knights as well as queens when translating to Wren. I then used the more efficient way for checking the diagonals described [https://www.geeksforgeeks.org/n-queen-problem-using-branch-and-bound/ here] and have now incorporated the improvements made to the Go version. |
This was originally based on the Java code [https://www.geeksforgeeks.org/minimum-queens-required-to-cover-all-the-squares-of-a-chess-board/ here] which uses a backtracking algorithm and which I extended to deal with bishops and knights as well as queens when translating to Wren. I then used the more efficient way for checking the diagonals described [https://www.geeksforgeeks.org/n-queen-problem-using-branch-and-bound/ here] and have now incorporated the improvements made to the Go version. |
||
Although far quicker than it was originally (it now gets to 7 knights in less than a minute), it struggles after that and needs north of |
Although far quicker than it was originally (it now gets to 7 knights in less than a minute), it struggles after that and needs north of 21 minutes to get to 10. |
||
<lang ecmascript>import "./fmt" for Fmt |
<lang ecmascript>import "./fmt" for Fmt |
||
Line 1,709: | Line 1,709: | ||
} |
} |
||
if (countSoFar <= maxCount) { |
if (countSoFar <= maxCount) { |
||
var si = (piece == "K") ? 0 : ti |
var si = (piece == "K") ? (ti-2).max(0) : ti |
||
var sj = (piece == "K") ? 0 : tj |
var sj = (piece == "K") ? (tj-2).max(0) : tj |
||
for (i in si...n) { |
for (i in si...n) { |
||
for (j in sj...n) { |
for (j in sj...n) { |
||
Line 1,858: | Line 1,858: | ||
. . . . . . . . . . |
. . . . . . . . . . |
||
Took |
Took 1276.522608 seconds. |
||
</pre> |
</pre> |