Solved LeetCode program · 960 of 1,000
#1329 · Sort the Matrix Diagonally
Original English source
Keep a shared matrix as an empty list of whole numbers. Keep a shared pieces as an empty list of whole numbers. Place 3 into matrix. Place 3 into matrix. Place 1 into matrix. Place 1 into matrix. Place 2 into matrix. Place 2 into matrix. Place 1 into matrix. Place 2 into matrix. Place 1 into matrix. Place 1 into matrix. Place 1 into matrix. Place 2 into matrix.
To trimpieces.
Repeat while the last position of pieces is at least 0.
Remove the last item from pieces.
To collect from row (a whole number) with column (a whole number). The currentrow is row. The currentcolumn is column.
Repeat while currentrow is less than 3 and currentcolumn is less than 4.
The index is currentrow times 4 plus currentcolumn. The value is item index of matrix. Place value into pieces. Add 1 to currentrow. Add 1 to currentcolumn.
To restore from row (a whole number) with column (a whole number). The currentrow is row. The currentcolumn is column. The cursor is 0.
Repeat while currentrow is less than 3 and currentcolumn is less than 4.
The index is currentrow times 4 plus currentcolumn. Set item index of matrix to item cursor of pieces. Add 1 to cursor. Add 1 to currentrow. Add 1 to currentcolumn.
To fix from row (a whole number) with column (a whole number). Trimpieces. Collect from row with column. Sort pieces. Restore from row with column.
For every column from 0 to 3, Fix from 0 with column. For every row from 1 to 2, Fix from row with 0. For every spot from 0 to 11, Show item spot of matrix.
Expected stdout
1 1 1 1 1 2 2 2 1 2 3 3