The TransCompilator

Solved LeetCode program · 907 of 1,000

#1254 · Number of Closed Islands

Medium Array chunk-19.md

Original English source

Keep a shared cells holding 1, 1, 1, 1, 0, 1, 1, 1, and 1. Keep a shared visited as a list of 9 zeros. Keep a shared islands of 0. Keep a shared levels of 0. Keep a shared spans of 0. Set levels to 3. Set spans to 3.

To sink from node (a whole number). If node is less than 0, return. If node is at least 9, return. If item node of cells is not 0, return. If item node of visited is 1, return. Set item node of visited to 1. The band is node divided by spans. The file is node modulo spans. If band is more than 0, sink from node minus spans. If band is less than levels minus 1, sink from node plus spans. If file is more than 0, sink from node minus 1. If file is less than spans minus 1, sink from node plus 1.

To probe from node (a whole number). If node is less than 0, return. If node is at least 9, return. If item node of cells is not 0, return. If item node of visited is 1, return. Set item node of visited to 1. The band is node divided by spans. The file is node modulo spans. If band is more than 0, probe from node minus spans. If band is less than levels minus 1, probe from node plus spans. If file is more than 0, probe from node minus 1. If file is less than spans minus 1, probe from node plus 1.

For every node from 0 to 8.
The band is node divided by spans. The file is node modulo spans. If band is 0 and item node of cells is 0, sink from node. If band is levels minus 1 and item node of cells is 0, sink from node. If file is 0 and item node of cells is 0, sink from node. If file is spans minus 1 and item node of cells is 0, sink from node.

For every node from 0 to 8.
If item node of cells is 0 and item node of visited is 0, probe from node, add 1 to islands.

Show islands.

Open in Playground Browse all 1,000 problems

Expected stdout

1