The TransCompilator

Solved LeetCode program · 784 of 1,000

#1020 · Number of Enclaves

Medium Array chunk-16.md

Original English source

The grid is a list of 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, and 0. The seen is a list of 16 zeros. The queue is an empty list of whole numbers. The count is 0.
For every cell from 0 to 15.
The rank is cell divided by 4. The column is cell modulo 4. The edge is 0. If rank is 0 or rank is 3 or column is 0 or column is 3, set edge to 1. If edge is 1 and item cell of grid is 1, set item cell of seen to 1, Place cell into queue, add 1 to count.

The head is 0.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. The rank is node divided by 4. The column is node modulo 4. If rank is more than 0 and item (node minus 4) of grid is 1 and item (node minus 4) of seen is 0, set item (node minus 4) of seen to 1, Place (node minus 4) into queue, add 1 to count. If rank is less than 3 and item (node plus 4) of grid is 1 and item (node plus 4) of seen is 0, set item (node plus 4) of seen to 1, Place (node plus 4) into queue, add 1 to count. If column is more than 0 and item (node minus 1) of grid is 1 and item (node minus 1) of seen is 0, set item (node minus 1) of seen to 1, Place (node minus 1) into queue, add 1 to count. If column is less than 3 and item (node plus 1) of grid is 1 and item (node plus 1) of seen is 0, set item (node plus 1) of seen to 1, Place (node plus 1) into queue, add 1 to count.

The total is 0.
For every cell from 0 to 15.
If item cell of grid is 1 and item cell of seen is 0, add 1 to total.

Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

3