Writing an APL solution for this question, and I've got it working, but not very well golfed. Try it online, any tips for golfing (other than remove whitespace)?
@Bubbler Is that second one just a general rule of thumb, because it isn't any shorter than the first. Actually, with one of the other golfs I figured out, it's one byte longer, though I might just be missing how to apply it in the second version
@ngn what do your explanations "neighbour graph" and "transitive closure" mean in this context? I think I can tell that neighbour graph is computing absolute distances between every 1 and every other 1, but in what way is it a "graph"? And the transitive closure - some logical operations turned into a matrix dot product, repeated until the match stops but what does that process do and why?