Write a function that counts the number of separate elements in the region.
A rectangular matrix, list of lists, with zero/one in each cell. A connected element is a collection of ones that share the border via an edge. Separate elements do not touch each other even via a corner. The elements don’t have holes.
The number of separate elements.
region = [
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 1, 1, 0],
[0, 1, 1, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 0],
[0, 1, 1, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0],
]
count_shapes(region) ➞ 3