我正在尝试实现一个 APL 程序(ClosedSeg),它可以计算布尔数组中孤立正方形段的总数。例如:
arr1
1 1 1 0 0 0 0
1 0 1 0 0 1 1
1 1 1 0 0 1 1
0 0 0 0 0 0 0
0 0 0 1 1 1 1
ClosedSeg arr1 ⍝ Four 1's border (non-linear) are minimum to be considered a segment.
2
arr2
1 1 1 1 0 0 0 0 0
1 0 0 1 0 1 1 1 0
1 1 1 1 0 1 0 1 0
1 1 0 0 0 1 1 1 1
0 0 0 0 0 0 1 0 1
0 0 0 0 0 0 1 1 1
ClosedSeg arr2 ⍝ Adjacent isolated segments counts.
4
arr3
1 1 1 1 0 0 0 0 0
1 0 0 1 0 1 1 1 0
1 0 1 1 0 1 0 1 1
1 1 1 0 0 1 1 0 1
0 0 0 0 0 0 1 0 1
0 0 1 0 0 0 1 1 1
0 1 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0 0
ClosedSeg arr3 ⍝ Any segment shapes are acceptable, note that diagonal 1's is not a segment border.
2
我被困在这一点上。