So I have a collection of trees, i.e. a forest, but it turns out all the trees in my particular data are just flat lists, so... my forest ended up being just a bunch of sticks in the ground?
@Adám Haha. Yes! This particular thing came up at work, and I found myself thinking of the APL solution and trying my best to find ways translating that into Groovy.
FWIW, I think that actually made the final code much cleaner.
@rabbitgrowth Cool. Did you know that if you store the state in a variable, then if you open the variable in the editor and have your functions update the variable, the editor will reflect the changes? Cheapo display ftw.
What I've been doing is match the height of the matrix to the height of my terminal, use the {⍺←⊢ ⋄ r⊣⍺ ⍺⍺{⍺←⊢ ⋄ r,∘⊂←⍺ ⍺⍺ ⍵}⍣⍵⍵⊃r←⊂⍵} trick from APLcart to print out all the intermediate results, pipe the output to less, then watch the animation by pressing space :)
> Write a function that, given a scalar or vector as the right argument and a positive (>0) integer chunk size n as the left argument, breaks the array’s items up into chunks of size n. If the number of elements in the array is not evenly divisible by n, then the last chunk will have fewer than n elements.
Yeah, that was a rather late addition. It also goes well together with ⊂ allowing a short left argument (appending the needed 0s), since ⍸⍣¯1 doesn't know how many 0s to put at the end.
⍸⍣¯1⊢⍸1 0 0 1 0 1 0 0 0
1 0 0 1 0 1
Heh, new way to remove trailing 0s in a Boolean vector using Under: ⊢⍢⍸
@Richard {⍵⊂⍨1@(1+⍺ׯ1+⍳⌈(≢⍵)÷⍺)⊢0⍨¨⍵}
Ooh, here's a different approach to building the Boolean: {⍵⊂⍨0=⍺|¯1+⍳≢⍵}
also did {⍵⊂⍨(⍴⍵)⍴⍺↑1} and thought it was nicer conceptually than (≢⍵) because it could be read as "make ⍺↑1 the same shape as ⍵", but yeah now I see it doesn't work with higher dimensional arrays
@Adám TIL the left argument of ⊂ could be shorter than the right argument
I mean, the question requires that "If the number of elements in the array is not evenly divisible by n, then the last chunk will have fewer than n elements."
Just thinking about it, why do you need the sign in {+/,×⍵}⌺3 3 ? Might be better to use {+/,⍵}⌺3 3 if you can as that's - at least in Dyalog - recognised and uses specialised fast C