Z
Zarathustra
I'm sure there must be a simple algorithm for giving the number of
"ones" that are connected, for example in an array like this:
int a[5][5] = {0};
a[0][0] = a[0][1] = a[1][1] = a[2][1] = a[0][4] = a[3][4]= a[4][4] =
a[4][0] = 1;
with all the rest still equal to zero.
1 0 0 1 1
0 0 0 0 0
0 0 0 0 0
1 1 1 0 0
1 0 0 0 1
such that the output in this case, can give 1 group of size 4, 1 group
of size 2, and 2 groups of size 1.
It looks simple, but everything I've tried so far hasn't caught all
possible shapes of groups of "1"s.
Any ideas would be greatly appreciated.
"ones" that are connected, for example in an array like this:
int a[5][5] = {0};
a[0][0] = a[0][1] = a[1][1] = a[2][1] = a[0][4] = a[3][4]= a[4][4] =
a[4][0] = 1;
with all the rest still equal to zero.
1 0 0 1 1
0 0 0 0 0
0 0 0 0 0
1 1 1 0 0
1 0 0 0 1
such that the output in this case, can give 1 group of size 4, 1 group
of size 2, and 2 groups of size 1.
It looks simple, but everything I've tried so far hasn't caught all
possible shapes of groups of "1"s.
Any ideas would be greatly appreciated.