Solved LeetCode program · 890 of 1,000
#1222 · Queens That Can Attack the King
Original English source
The queenrows is a list of 0, 1, 4, 0, 3, and 2. The queencols is a list of 1, 0, 0, 4, 3, and 4. The kingrow is 0. The kingcol is 0. The nearest is a list of 9 zeros. The pickrow is a list of 9 zeros. The pickcol is a list of 9 zeros.
For every spot from 0 to 5.
The queenrow is item spot of queenrows. The queencol is item spot of queencols. The down is queenrow minus kingrow. The across is queencol minus kingcol. The aligned is 0. If down is 0 or across is 0 or the absolute value of down is the absolute value of across, set aligned to 1.
If aligned is 1.
The stepdown is 0. If down is less than 0, set stepdown to -1. If down is more than 0, set stepdown to 1. The stepacross is 0. If across is less than 0, set stepacross to -1. If across is more than 0, set stepacross to 1. The slot is (stepdown plus 1) times 3 plus stepacross plus 1. The distance is the absolute value of down plus the absolute value of across. The better is 0. If item slot of nearest is 0, set better to 1. If distance is less than item slot of nearest, set better to 1. If better is 1 and distance is more than 0, set item slot of nearest to distance, set item slot of pickrow to queenrow, set item slot of pickcol to queencol.
The board is a list of 64 zeros.
For every slot from 0 to 8.
If item slot of nearest is more than 0, set item (item slot of pickrow times 8 plus item slot of pickcol) of board to 1.
The rows is an empty list of whole numbers. The cols is an empty list of whole numbers.
For every depth from 0 to 7.
For every column from 0 to 7.
If item (depth times 8 plus column) of board is 1, Place depth into rows, Place column into cols.
The line is empty text. Place "[" into line.
For every spot from 0 to the last position of rows.
If spot is more than 0, Place "," into line. The rowtext is format whole number item spot of rows as text. The coltext is format whole number item spot of cols as text. Place "[" into line. Place rowtext into line. Place "," into line. Place coltext into line. Place "]" into line.
Place "]" into line. Show line.
Expected stdout
[[0,1],[1,0],[3,3]]