Jump to content

N-queens problem: Difference between revisions

m
→‎{{header|Uiua}}: Tweaked the algorithm
m (→‎{{header|Uiua}}: Tweaked the algorithm)
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.
 
Starts with an empty array of values, and stepwiseN expandstimes andadds filterseach of 0-(N-1) at the end, only keeping those that still validate.
 
<syntaxhighlight lang="Uiua">
N ← 8
Good ← =1⧻◴[⧻◴ ⟜⧻◴⟜(∩(⧻◴)⊃(+|-)⇡⧻.) ⟜⧻]
⊙◌⍥(⊏⊚≡Good.☇1⊞⊂⇡,),[[]]N
RowString ← ⊂"≡(≡(/(⊂⊂)@|"/⊂⍜(⊡|"Q|"◌@Q◌):↯N"↯:@_|")⊸⧻)
≡≡RowString ⟜⧻⊙◌
</syntaxhighlight>
{{out}}
<pre>
92
╭─
╷ "|Q|_|_|_|_|_|_|_|"
╷ "|_|_|_|_|Q|_|_|_|"
"|_|_|_|_|_|_|_|Q|"
"|_|_|_|_|_|Q|_|_|"
"|_|_|Q|_|_|_|_|_|"
"|_|_|_|_|_|_|Q|_|"
"|_|Q|_|_|_|_|_|_|"
"|_|_|_|Q|_|_|_|_|"
"|Q|_|_|_|_|_|_|_|"
"|_|_|_|_|_|Q|_|_|"
"|_|_|_|_|_|_|_|Q|"
"|_|_|Q|_|_|_|_|_|"
"|_|_|_|_|_|_|Q|_|"
"|_|_|_|Q|_|_|_|_|"
"|_|Q|_|_|_|_|_|_|"
"|_|_|_|_|Q|_|_|_|"
 
...etc...
</pre>
 
171

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.