Simplified: There is an array
[[0,0,0,0,0], [0,1,1,0,0], [1,1,0,0,1], [0,1,0,0,1], [0,0,0,0,0]] How to write closed areas, consisting of units in separate arrays? As an option
[[0,1,1], [1,1,0], [0,1,0]] [[1], [1]] I only have the option to run through all the rows of the original array, writing down the beginning and end of a sequence of units in a separate list, and after passing the next line compare overlaps. But most likely it is a bicycle crutch, and there is a decent rational solution. As always, you can not write the code, but hint how this is called correctly in bourgeois.