The TransCompilator

Solved LeetCode program · 923 of 1,000

#1284 · Minimum Number of Flips to Convert Binary Matrix to Zero Matrix

Hard Array chunk-19.md

Original English source

The matrix is a list of 0, 0, 0, and 1. The rows is 2, while the columns is 2. The weights is a list of 1, 2, 4, and 8. The patterns is a list of 4 zeros.
For every cell from 0 to 3.
The band is cell divided by columns. The file is cell modulo columns. The pattern is item cell of weights. If band is more than 0, set pattern to pattern plus item (cell minus columns) of weights. If band is less than rows minus 1, set pattern to pattern plus item (cell plus columns) of weights. If file is more than 0, set pattern to pattern plus item (cell minus 1) of weights. If file is less than columns minus 1, set pattern to pattern plus item (cell plus 1) of weights. Set item cell of patterns to pattern.

The seen is a list of 16 zeros. The distance is a list of 16 zeros. The queue is a list of 16 zeros. The start is 8. Set item start of seen to 1. Set item 0 of queue to start. The count is 1. The head is 0. The answer is -1.
Repeat while head is less than count and answer is less than 0.
The state is item head of queue. Add 1 to head. If state is 0, set answer to item state of distance.
If state is not 0.
For every cell from 0 to 3.
The next is exclusive or of state and item cell of patterns.
If item next of seen is 0.
Set item next of seen to 1. Set item next of distance to item state of distance plus 1. Set item count of queue to next. Add 1 to count.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

3