Solved LeetCode program · 395 of 1,000
#0529 · Minesweeper
Original English source
Keep a shared board holding 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, and 0. Keep a shared labels holding "E", "M", "B", "1", "2", "3", "4", "5", "6", "7", and "8". Keep a shared height of 4. Keep a shared width of 5. Keep a shared nearby of 0. Keep a shared rowsteps holding -1, -1, -1, 0, 0, 1, 1, and 1. Keep a shared colsteps holding -1, 0, 1, -1, 1, -1, 0, and 1.
To count from row (a whole number) with column (a whole number). Set nearby to 0.
For every step from 0 to 7.
The side is row plus item step of rowsteps. The depth is column plus item step of colsteps. The here is side times width plus depth. If side is at least 0 and side is less than height and depth is at least 0 and depth is less than width, If item here of board is 1, add 1 to nearby.
To reveal from row (a whole number) with column (a whole number). If row is less than 0 or row is at least height or column is less than 0 or column is at least width, return. The cell is row times width plus column. If item cell of board is not 0, return. Count from row with column. If nearby is more than 0, The score is nearby, set item cell of board to score plus 2, return. Set item cell of board to 2. Reveal from row minus 1 with column minus 1. Reveal from row minus 1 with column. Reveal from row minus 1 with column plus 1. Reveal from row with column minus 1. Reveal from row with column plus 1. Reveal from row plus 1 with column minus 1. Reveal from row plus 1 with column. Reveal from row plus 1 with column plus 1.
Reveal from 3 with 0. The line is empty text.
For every cell from 0 to 19.
The mark is item cell of board. The label is item mark of labels. Place label into line. If cell modulo width is width minus 1, show line, set line to empty text.
Expected stdout
B1E1B B1M1B B111B BBBBB