-1

I'm trying to implement an APL program (ClosedSeg) that could count the total amount of isolated square segments in an array of Boolean. For example:

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

I'm stuck at this.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Have you tried anything at all? All I see here is a question you've been given. – Orbling Aug 14 '13 at 19:36
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Oct 11 '13 at 23:29

1 Answers1

1

That's a nice puzzle for a boring evening. However, the general idea of SO is to discuss "problems with code" and not to post "specifications" in order to get a cheap coder. So, generally speaking, you should post some code which shows that you tried yourself, as Orbling suggested. However, the APL-Community (in general and on SO) is usually very friendly, helpful - and also interested in puzzles - so chances are that you actually get a solution.

Could you pls. also specify how to handle "square and more" - would the following example count?

Also: which APL are you using and which version? Hint: Dyalog 16 added the "Stencil"-operator which might be useful to solve this - if you use Dyalog...

1 1 1 1 0 0 0 0 0
1 0 0 1 1 1 1 1 0
1 0 1 1 0 0 0 1 0
1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
MBaas
  • 7,248
  • 6
  • 44
  • 61