logoalt Hacker News

xelxebartoday at 5:28 AM1 replyview on HN

With an OR 2-scan, you can avoid the negation. Here's how I'd do it in APL: {⍵⌿⍨2∨⌿0⍪' '≠⍵}. In general, I find that boolean 2-scans pop up quite a bit in real-world APL usage. It's worth working through them. I have a short article [0] on the subject, if you're interested.

It's also worth thinking through how all 16 boolean operators work on boolean masks. E.g. what do msk≠msk2, msk<msk2, msk≤msk2 etc. mean? In my experience, the important part is to find crisp domain-specific meanings for these patterns. In general, really, that's how you gain APL fluency. In the same way that reading fluency requires chunking so that letters "disappear", APL fluency requires familiarity with semantic phrases, so you stop thinking in the individual symbols.

[0]:https://blog.wilsonb.com/posts/2023-07-24-suggestivity-and-i...


Replies

kcroarkintoday at 9:43 AM

(crossing fingers I one shot formatting correctly) I use 2-wise for figuring out which water surfaces to draw: ⍉l⊤⍸∊(chunk=¯1)(2>⌿⍤2⍪⍤2)⊢0⍴⍨⊃l

- ⍪⍤2 add padding on top of surface of bit mask of water

- 2>⌿⍤2 identify where surface is exposed by seeing if air comes after water vertically

- ⍉l⊤⍸∊ collapse and get where water is in chunk position format row-by-row