| Bytes | Lang | Time | Link |
|---|---|---|---|
| 029 | Jelly | 250224T231754Z | Jonathan |
| 113 | Charcoal | 250221T102538Z | Neil |
Jelly, 29 bytes
UƬŒD€Ẏ;;Zḟ€1IȦ
64R_⁵ṠŒ!Qs€8ÇƇ
A niladic Link that yields a list of boards, each being a list of rows of integers:
-1 Queen
0 Obstacle
1 Empty
Don't try it online it won't complete, even if you run it locally (\$64!\$ is big :D).
Try a 3x3 with 3 queens and one obstacle (64 -> 9; ⁵ (\$10\$) -> 4; and 8 -> 3. The footer pretty-prints.)
How?
UƬŒD€Ẏ;;Zḟ€1IȦ - Link 1, isValid?: Board
(list of lists of {-1:queen; 0:obstacle; 1:empty})
Ƭ - collect up while distinct under:
U - reverse each
ŒD€ - diagonals of each
Ẏ - tighten -> diagonals + antidiagonals
; - {diagonals + antidiagonals} concatenate {Board}
Z - transpose {Board} -> Columns
; - {diagonals + antidiagonals + Board} concatenate {Columns}
ḟ€1 - filter all ones (empties) from each
I - forward deltas of each
Ȧ - any any all? -> 0 if any zeros are present
(i.e. queens staring at each other)
else 1
64R_⁵ṠŒ!Qs€8ÇƇ - Main Link: no arguments
64R - [1..64]
_⁵ - subtract ten -> [-9..54]
Ṡ - signs -> [-1]*9 + [0] + [1]*54 (queens, obstacle, empties)
Œ! - all permutations
Q - deduplicate
s€8 - split each into rows of length eight
Ƈ - keep those for which:
Ç - call Link 1
Real world version, 54 bytes
UƬŒD€Ẏ;Z¹Ƈ€IȦ
8œc2r/ṖḊ;€Ʋ€Ẏµ8RḟḊ;Ḣ©⁸ṭṬ€z0Ṗ€®¦z2Œ!ÇƇQ)Ẏ
Yields a list of boards, each being a list of rows of integers:
1 Queen
2 Obstacle
0 Empty
Still a brute force, but limiting the search space to boards with seven rows containing single queens covering exactly six different columns (with one repeat), and the remaining row containing two queens covering the other two columns (with the obstacle placed in the repeated column).
Don't try it online it still won't complete, but it ran in ~15 mins offline for me and produced the \$128\$ valid boards.
But, here you can run a version that only considers one of the subsets of boards it considers. This accepts a triple of integers \$(B, L, R)\$ with \$0 < L < B < R < 9\$, where \$B\$ is the column of the obstacle, \$L\$ is the column of the queen to its left, and \$R\$ is the column of the queen to its right.
Charcoal, 113 bytes
≔E⁸E⁸E³E⁸⟦⁻ιπ⁺λ×π⊖ν⟧θF⁷F⁷¿κ«≔⟦υ⟧ηF⁸F⎇⁻λι⟦⁸⟧⟦κ…⊕κ⁸⟧≔ΣEμEΦη⬤§§θλν⁼π⁻π⎇‹ιλ⁻ς§§§θικσς⁺π⟦⟦λν⟧⟧ηFη«DE⁸⭆⁸§.Q№λ⟦μξ⟧JκιKD⎚
Attempt This Online! Link is to verbose version of code. Uses K as the obstacle, as I felt that was appropriate for chess. Explanation:
≔E⁸E⁸E³E⁸⟦⁻ιπ⁺λ×π⊖ν⟧θ
For each square, calculate the squares on higher rows of the board (and also a bunch of squares that aren't on the board) that are attacked. (Since queens are placed starting at the top and working down, and two queens are never placed in the same row unless the obstacle is between then, we only need to check for potential queens attacking existing queens in higher rows.)
F⁷F⁷¿κ«
Loop over all possible squares for the obstacle, plus some impossible ones. (But we have to omit the first column, otherwise the code fails with an empty sum later.)
≔⟦υ⟧η
Start with no queens placed so far.
F⁸F⎇⁻λι⟦⁸⟧⟦κ…⊕κ⁸⟧
Loop through all rows, but split the row with the obstacle so it is looped over twice (since there will be two queens on this row).
≔ΣEμEΦη⬤§§θλν⁼π⁻π⎇‹ιλ⁻ς§§§θικσς⁺π⟦⟦λν⟧⟧η
Looping over the squares of this row or part row, collect those sets of queens which aren't attacked by the proposed queen, make new sets including the proposed queen, and collect all of the resulting sets back to the list of queen placements.
Fη«
Loop over all of the found sets of queens for this obstacle.
D
Leave a blank line between boards.
E⁸⭆⁸§.Q№λ⟦μξ⟧JκιKD
Output the board.
⎚
Clear the canvas ready for the next board.