Elias Mårtenson<p><strong>Kap marketing post</strong></p><p>So, I saw Leetcode question 73, whose description is as follows:</p><blockquote><p>Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.</p></blockquote><p>In most popular programming languages, something like this is somewhat annoying, forcing you to write some loops that kind of hides what you really want to do.</p><p>Even in Excel, I think this will be frustrating, but I'm not an Excel expert.</p><p>But if you think about it, if you create a new matrix that contains a bitmask where every cell is 1 where the original matrix contains a nonzeoro value, you can simply check if each row contains all ones, and then do the same check on each column.</p><p>Finally, we'll just multiply the new mask with the original matrix, which gives us the result we need:</p><pre><code>{<br> mask ← 0≠⍵<br> rows ← ∧/mask<br> cols ← ∧⌿mask<br> sel ← rows ∧⌻ cols<br> sel × ⍵ <br>}<br></code></pre><p>Of course, the above is written out with temporary variables. In practice, I'd write it as a single expression like so:</p><pre><code>{ ⍵ × (∧/)«∧⌻»(∧⌿) 0≠⍵ }<br></code></pre><p>And of course, people will complain that it's unreadable and whatnot, but these two versions are equivalent, and the latter just takes advantage of the <code>«</code> and <code>»</code> symbols to combine functions.</p><p>If anyone has a problem they would otherwise use Excel or some python program to solve, share it with me to see if I can use it to show that Kap can be a better solution. 🙂</p><p>(and if I can't, that's even better, because then I have a reason to improve the software)</p><p><a href="https://functional.cafe/tags/kap" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>kap</span></a> <a href="https://functional.cafe/tags/apl" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>apl</span></a> <a href="https://functional.cafe/tags/programming" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>programming</span></a></p>