The TransCompilator

Solved LeetCode program · 948 of 1,000

#1314 · Matrix Block Sum

Medium Array chunk-19.md

Original English source

Keep a shared matrix as an empty list of whole numbers. Keep a shared total of 0. Place 1 into matrix. Place 2 into matrix. Place 3 into matrix. Place 4 into matrix. Place 5 into matrix. Place 6 into matrix. Place 7 into matrix. Place 8 into matrix. Place 9 into matrix.

To sweep from row (a whole number) with column (a whole number). Set total to 0.
For every other from 0 to 8.
The otherrow is other divided by 3. The othercolumn is other modulo 3. The rowgap is the absolute value of (otherrow minus row). The colgap is the absolute value of (othercolumn minus column). The piece is item other of matrix. If rowgap is at most 1 and colgap is at most 1, add piece to total.

For every cell from 0 to 8.
The row is cell divided by 3. The column is cell modulo 3. Sweep from row with column. Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

12
21
16
27
45
33
24
39
28