Say you had an array in the form:
[
[2, 2, 3, 4],
[2, 3, 5, 5],
[2, 2, 2, 5],
[3, 2, 2, 4],
]
and wanted to find coordinates of numerically contiguous blocks, in this case:
[
# the 2s:
[(0,0), (0,1), (1,0), (2,0), (2,1), (2,2), (3,1), (3,2)],
# and the 5s:
[(1,2), (1,3), (2,3)]
]
how would you do it?
You can try a flood fill algorithm on each cell. (Note: flag already processed cells also during fills to not take them into account multiple times)