N-queens problem: Difference between revisions
Content added Content deleted
m (→{{header|Uiua}}: Tweaked the algorithm) |
|||
Line 16,701: | Line 16,701: | ||
`Good` checks that a (maybe partial) solution is valid, by checking that each number is unique, each number+index is unique and each number-index is unique. |
`Good` checks that a (maybe partial) solution is valid, by checking that each number is unique, each number+index is unique and each number-index is unique. |
||
Starts with an empty array of values, and |
Starts with an empty array of values, and N times adds each of 0-(N-1) at the end, only keeping those that still validate. |
||
<syntaxhighlight lang="Uiua"> |
<syntaxhighlight lang="Uiua"> |
||
N ← 8 |
N ← 8 |
||
Good ← =1⧻◴[ |
Good ← =1⧻◴[⧻◴⟜(∩(⧻◴)⊃+-⇡⧻.)⟜⧻] |
||
⊙◌⍥(⊏⊚≡Good.☇1⊞⊂⇡,),[[]]N |
|||
≡(≡(/(⊂⊂)@|/⊂⍜(⊡|@Q◌):↯:@_)⊸⧻) |
|||
≡≡RowString ⟜⧻⊙◌ |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
92 |
92 |
||
╭─ |
╭─ |
||
╷ " |
╷ "Q|_|_|_|_|_|_|_" |
||
╷ " |
╷ "_|_|_|_|Q|_|_|_" |
||
" |
"_|_|_|_|_|_|_|Q" |
||
" |
"_|_|_|_|_|Q|_|_" |
||
" |
"_|_|Q|_|_|_|_|_" |
||
" |
"_|_|_|_|_|_|Q|_" |
||
" |
"_|Q|_|_|_|_|_|_" |
||
" |
"_|_|_|Q|_|_|_|_" |
||
" |
"Q|_|_|_|_|_|_|_" |
||
" |
"_|_|_|_|_|Q|_|_" |
||
" |
"_|_|_|_|_|_|_|Q" |
||
" |
"_|_|Q|_|_|_|_|_" |
||
" |
"_|_|_|_|_|_|Q|_" |
||
" |
"_|_|_|Q|_|_|_|_" |
||
" |
"_|Q|_|_|_|_|_|_" |
||
" |
"_|_|_|_|Q|_|_|_" |
||
etc |
...etc... |
||
</pre> |
</pre> |
||