« first day (2256 days earlier)      last day (398 days later) » 

4:42 AM
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?
 
 
2 hours later…
6:20 AM
@B.Wilson Maybe it is a mixed forest, i.e. just a wood matrix?
 
 
4 hours later…
10:20 AM
@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.
 
 
3 hours later…
1:15 PM
Playing around with cellular automata :)
 
@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.
 
1:30 PM
Didn't know that, thanks for the tip!
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 :)
 
1:44 PM
@rabbitgrowth Try this:
mat←4 5⍴⎕A
⎕ED'mat'
{mat⌽⍨←1⊣⎕DL.5}¨⍳10
 
ooh, I love this!
much better than my hack
 
2:00 PM
Welcome to APL Quest 2019-1! Today's quest is Chunky Monkey:
> 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.
 
Had to rethink this one a few times
came up with this
(⊢⊂⍨≢⍤⊢⍴⊣↑1⍨)
 
I like that.
 
must be other ways
 
Well, I wrote the explicit version: {⍵⊂⍨(≢⍵)⍴⍺↑1}
Doing it with Stencil gets ugly fast.
Oh, it can be done with too.
{(1+⌊⍺÷⍨¯1+⍳≢⍵)⊆,⍵}
 
ah yes!
 
2:07 PM
We could do takes and drops, or multiple masks too, but it is just wasteful.
Key can do the same as
{(⌊⍺÷⍨¯1+⍳≢⍵)⊂⍤⊢⌸,⍵}
 
I first tried to put 1's in a vector of 0's using @ but that gives to complicated code
 
Ah yes, or use ⍸⍣¯1
 
or a zero filled matrix with the first column filled with 1's and then enlist
@Adám also tried that :)
 
This seems to work: {⍵⊂⍨⍸⍣¯1⊢i∩1+⍺×0,i←⍳≢⍵}
i∩ is easier than computing the range :-)
 
oef... food for thought
 
2:18 PM
I'm not saying this is good.
But let's think about it. Given n and the length (l) of the right argument, how many segments will we have?
 
⌈l÷n
 
Right, so then we need to produce that many segments of 1 0 0….
The indices of the 1s will be 1,(1+n),(1+2×n),…
 
yes
 
OK, so that's the same as n×⍳⌈l÷n with ⎕IO←0
1+nׯ1+⍳⌈l÷n in ⎕IO←1
Full solution: {⍵⊂⍨⍸⍣¯1⊢1+⍺ׯ1+⍳⌈(≢⍵)÷⍺}
 
incredible that ⍣¯1 alsio likes ⍸
 
2:26 PM
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+⍳≢⍵}
 
that's a smart one
 
⎕IO←0 would make that nice when tacit: ⊢⊂⍨0=|∘⍳∘≢
I think we've solved this one :-)
 
thanks!
 
Next week, @RikedyP will run 2019-2: Making the Grade.
 
@Adám I was told that the forums are a more appropriate place for the mapl trivia. Threw the two bullet points here: forums.dyalog.com/viewtopic.php?f=20&t=1903
 
2:37 PM
Nice. I still think it could go under a Trivia heading on the Dyalog Ltd or Dyalog APL page.
There are probably more trivia that could be collected there, e.g. about the duck.
 
Good idea.
 
3:01 PM
oh no I missed it, thought it was going to be an hour later :(
I also tried to do it with instead of , but overcomplicated it and did {⍵⊆⍨x↑⍺/⍳⌈⍺÷⍨x←≢⍵}⍥,
 
3:12 PM
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
 
@rabbitgrowth which is not very different. And ⍥ always gives bonus points :)
 
:)
Well, learned a lot today! I tried to come up with a solution that doesn't use dyadic or but couldn't think of anything. Now I see you could use
 
3:31 PM
@Adám Neat. Open up a b←30 30⍴' ' in an editor and watch _←{_←⎕DL 0.1 ⋄ b∘←' ⎕'⌷⍨⊂m←{c←4⊃,⍵ ⋄ c⌷(3∘=,∊∘3 4)+/,⍵}⌺3 3⊢' ⎕'⍳⍵}⍣≡' ⎕'⌷⍨⊂?30 30⍴2 go!
@rabbitgrowth Yeah, I thought it was rescheduled to 15:00 UTC, too.
 
@B.Wilson could you tell me how? p.s. gives an index error?
 
@Richard Oh, set ⎕IO←0 first :P
 
ah :)
 
@Richard Did it come alive?
 
yes!
 
3:47 PM
Nice. So ∘← is used instead of for mutating b outside the dfn?
 
@rabbitgrowth Yeah, it's supposedly a hack, but it's a common one.
Note that modified assignment also will mutate variables in the outer scope, so the ⊢← is mostly the same.
 
How does ∘← work? Aren't you supposed to put a function, not an operator, before for modified assignment?
 
@Adám without looking at any other answer, using a trick i recently learned {↓⍵⍴⍨⍺,⍨⌊⍺÷⍨≢⍵}
i do love my
 
I think that fails if ≢⍵ isn't a multiple of ?
 
4:02 PM
nope
thats why theres a
 
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."
 
ah
i thought the requirement was to drop them
yeah partition would be the best way then
 
4:36 PM
@rabbitgrowth That's why it's considered a hack. ∘← leverages an unintended behavior in the implementation of .
Though, co-dfns explicitly has support for that syntax :D
 
is there any to use while also respecting ]boxing?
doing a bit of debugging
hrm, found display in dfns
 
4:52 PM
well, that was fun:
(⎕IO←1)
⎕ED'life'
seed←{1@(⊂,⍨⌈⍵÷2)⊢0⍴⍨,⍨⍵}
next←{(∊∘⍺×⊢){+/,×⍵}⌺3 3⊢⍵}
draw←{(' ',1↓⎕D)[1+⍵]}
_←((1∪⍳⊢⍤/⍨1-⍨∘?2⍴⍨⊢)9)next{x⊣life⊢←draw⊢x←⍺ ⍺⍺ ⍵⊣⎕DL 0.5}⍣12⊣x⊣life←draw⊢x←seed 25
(please do let me know if any of this could be written better!)
 
5:23 PM
Next is how you get the next generation right?
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
 
 
3 hours later…
8:18 PM
@Adám oops I'm very late but I have this in my library (not sure if it's valid Dyalog): ⊢⊂⍨⊣|⍳⍤≢⍤⊢
yeah my ⊂ assumes all non-1 values are zeroes, Dyalogs does weird stuff I don't really understand the need for
something like ⊢⊂⍨⎕io∘=⍤(⊣|⍳⍤≢⍤⊢) should work, also accounting for different index origin
wait I'm dumb you can drop the sames
⊢⊂⍨⎕io∘=⍤|∘⍳∘≢
@Adám yeah ok turns out it's the same as this one after all :)
 

« first day (2256 days earlier)      last day (398 days later) »