Solved LeetCode program · 794 of 1,000
#1030 · Matrix Cells in Distance Order
Original English source
The rows is 2, while the columns is 2. The centerrow is 0, while the centercolumn is 1. The keys is an empty list of whole numbers.
For every cell from 0 to 3.
The across is cell divided by columns. The down is cell modulo columns. The steps is the absolute value of (across minus centerrow). The side is the absolute value of (down minus centercolumn). The key is (steps plus side) times 100 plus cell. Place key into keys.
For every spot from 0 to 3.
For every look from spot plus 1 to 3.
If item look of keys is less than item spot of keys, swap item spot of keys and item look of keys.
For each key in keys.
The cell is key modulo 100. The across is cell divided by columns. The down is cell modulo columns. The line is empty text. Place format whole number across as text into line. Place "," into line. The side is format whole number down as text. Place side into line. Show line.
Expected stdout
0,1 0,0 1,1 1,0