« first day (2494 days earlier)      last day (321 days later) » 

3:59 AM
@RubenVerg I'm trying to get ngn-k packaged for my Linux distro, but the distro maintainers initially rejected my submission because they thought the code was intentionally obfuscated.
It's taken a bit of back and for to get them to the merely incredulous state.
 
3 hours later…
7:29 AM
@Adám
⌽⍤↑'⎕'/⍨¨⍳
 
3 hours later…
10:30 AM
@Silas why:(((
what's the fun in making intentionally unparseable code?
this feels like a bad version of code golf
 
2 hours later…
1:00 PM
Welcome to APL Quest 2022-5! Today's quest is Stairway to Heaven:
> Write a function that:
> • takes a scalar integer argument, n, in the range 0-100.
> • returns a character matrix comprised of spaces and that resembles an n-level left-to-right ascending stairway.
E.g. if given 10, return this matrix:
         ⎕
        ⎕⎕
       ⎕⎕⎕
      ⎕⎕⎕⎕
     ⎕⎕⎕⎕⎕
    ⎕⎕⎕⎕⎕⎕
   ⎕⎕⎕⎕⎕⎕⎕
  ⎕⎕⎕⎕⎕⎕⎕⎕
 ⎕⎕⎕⎕⎕⎕⎕⎕⎕
⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
There are at least a couple of good approaches to this.
⌽⍤↑'⎕'⍴¨⍨⍳
Right, but can you stay flat?
@RubenVerg Do you know the defintion of ¨?
{' ⎕'[1+⍵<∘.+⍨⍳⍵]}
was about to send the same thing!
Me too.
1:05 PM
@Adám rank zero + some boxing stuff?
Yes: ⊂⍤f⍥⊃⍤0
So if we put this into your solution, we have ⌽⍤↑'⎕'⊂⍤⍴⍤0⍥⊃⍨⍳
⌽⍴∘'⎕'⍤0⊢⍳⍵?
or ⌽'⎕'⍴⍨⍤0⍳
Yes, nice.
Even better might be moving the to the right of 0 so it isn't done every time around the loop.
Here's another fun one: {⌽↑,\⍵⍴'⎕'}
Can you spot the cases where it'll fail?
I assume it's with 0 but I can't figure out why
That's one of them.
1:14 PM
@rabbitgrowth here is another one, quite similar: ' ⎕'⊇⍨0≤∘.-∘⌽⍨⍤⍳
and 1 as well
0⍴'⎕' gives '' and ,\ is a no-op. So are and . But we wanted 0 0⍴'' not ''
@rabbitgrowth Right!
So that's why the APLcart entry for prefixes of a vector is ,¨,\ and not just ,\
@Adám does the tryapl page consider 1 an extra-point case?
@rabbitgrowth Yes. (Double your backticks!)
1:17 PM
oops
@RubenVerg Yes, both 1 and 0.
… but it also normalises your result to a matrix, so it'll accept '⎕' and ,'⎕' for 1!
Maybe I should remove that normalisation?
Sounds like a good idea
liking '⎕' but not '' seems like weird behavior, they are both the correct result when matricized
@RubenVerg ⊇⍨?
1:20 PM
@RubenVerg No, the matrix version of '' is 1 0⍴'' not 0 0⍴''
@RubenVerg Hey, we should update that page to include my user meeting talk.
@Adám ⍴⍪'' gives 0 1, not 1 0
@RubenVerg Yes, but the normalisation done is creating a matrix that displays identically.
ah, I see
@RubenVerg ah I see, my brain just parsed it as
didn't even notice it was the other way round
Anyway, did we finish this one?
1:27 PM
{⌽' ⎕'[1+∘.≥⍨⍳⍵]}
nothing terribly exciting
No, but you might want to reverse the Boolean matrix for performance.
oh, why is that faster?
A ' ⎕'-array takes up 16 times as much memory per element as a Boolean array!
      'cmpx'⎕CY'dfns'
      A←{⌽' ⎕'[1+∘.≥⍨⍳⍵]}
      B←{' ⎕'[1+⌽∘.≥⍨⍳⍵]}
      cmpx'A 1000' 'B 1000'
  A 1000 → 7.0E¯4 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  B 1000 → 3.2E¯4 | -55% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
Another option is reversing the indices, but they use 8 bits per element, so I'd expect performance to fall between these two…
hm, it seems non-obvious that it's slower to reverse an array that takes up more memory
In today's world, computation is mostly free. The limit is memory read/write.
1:32 PM
do arrays own their memory?
Not sure what that means.
do, say, vec and 1↓vec duplicate all elements of the vector or does the second array in some way point to the same buffer as the first one?
@Adám so after you reverse it, you'd have to write it back, and that's the slow part?
1↓vec duplicates. However, two arrays can point to exactly the same data.
@rabbitgrowth Well, a reversal can be done in-place (unless ↑)
@Adám … yup:
      C←{' ⎕'[⌽1+∘.≥⍨⍳⍵]}
      cmpx'A 5000' 'B 5000' 'C 5000'
  A 5000 → 1.6E¯2 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  B 5000 → 1.1E¯2 | -33% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  C 5000 → 1.3E¯2 | -18% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
Should we do a grand comparison of all our solutions?
Oh, btw, I suspect changing ⎕IO to 0 might provide a speed-up for the indexing solutions.
yes please!
1:38 PM
I'll bet the reshape one is faster than the indexing ones
      B←{' ⎕'[1+⌽∘.≥⍨⍳⍵]}
      B0←{i←⍳⍵ ⋄ ⎕IO←0 ⋄ ' ⎕'[⌽∘.≥⍨i]}
      cmpx'B 1000' 'B0 1000'
  B 1000  → 3.7E¯4 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  B0 1000 → 2.3E¯4 | -38% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
We want to use before changing ⎕IO to avoid 1+ there.
do we?
i don't think anything's different if the numbers are [0..n) instead of [1..n]
How will you generate 1…n with ⎕IO←1?
wdym?
for ∘.≥⍨ the numbers could start from 0, 1, or 95, it doesn't matter as long as they're in sequence
D'oh. Stupid me.
1:45 PM
I don't get it. Why not just {⎕IO←0 ⋄ ' ⎕'[⌽∘.≥⍨⍳⍵]}?
Exactly @RubenVerg's point.
Sorry, I'm on mobile and a bit slow
what does a star next to a cmpx result mean?
The results differed.
oh right forgot to account for index origin
anyway, I'm getting a lot of fluctuation in the results
1:47 PM
You might be using too small an argument.
      cmpx 'A 5000' 'B 5000' 'C 5000' 'D 5000'
  A 5000 → 2.2E¯2 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  B 5000 → 2.0E¯2 | -12% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  C 5000 → 8.1E¯3 | -64% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  D 5000 → 2.2E¯2 |  +1% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
      cmpx 'A 5000' 'B 5000' 'C 5000' 'D 5000'
  A 5000 → 2.2E¯2 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  B 5000 → 1.9E¯2 | -16% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  C 5000 → 7.4E¯3 | -67% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  D 5000 → 2.8E¯2 | +25% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
B is your RV2, it seems to change a lot
That is a lot of fluctuation. Could your computer be busy with something?
@RubenVerg I'm renaming them to increase readability…
@Adám not really, but it's also not a great machine, might just be busy with background OS stuff
I'll just wait for yours :)
OK, I'm using
  ⎕CLEAR
  A←⌽⍤↑'⎕'⍴¨⍨⍳
  B←{' ⎕'[1+⍵<∘.+⍨⍳⍵]}
  C←{⎕IO←0 ⋄ ' ⎕'[(⍵-2)<∘.+⍨⍳⍵]}
  D←⌽'⎕'⍴⍨⍤0⍳
  E←{⎕IO←0 ⋄ ' ⎕'[0≤∘.-∘⌽⍨⍤⍳⍵]}
  F←{' ⎕'[1+⌽∘.≥⍨⍳⍵]}
  G←{⎕IO←0 ⋄ ' ⎕'[⌽∘.≥⍨⍳⍵]}
  'cmpx'⎕CY'dfns'
  cmpx,∘' 1000'¨⎕A⎕NL¯3
First run:
  A 1000 → 6.2E¯4 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  B 1000 → 7.2E¯4 | +15% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  C 1000 → 6.0E¯4 |  -4% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  D 1000 → 6.2E¯4 |  -1% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  E 1000 → 5.6E¯4 | -11% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  F 1000 → 3.6E¯4 | -42% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  G 1000 → 2.3E¯4 | -64% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
Second run:
  A 1000 → 6.2E¯4 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  B 1000 → 7.2E¯4 | +17% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  C 1000 → 6.4E¯4 |  +3% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  D 1000 → 6.2E¯4 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  E 1000 → 5.6E¯4 | -10% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  F 1000 → 3.6E¯4 | -42% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  G 1000 → 2.3E¯4 | -63% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
But I think we can do better than {⎕IO←0 ⋄ ' ⎕'[⌽∘.≥⍨⍳⍵]}
      cmpx'A 1000' 'G 1000' 'H 1000'
  A 1000 → 6.0E¯4 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  G 1000 → 2.3E¯4 | -62% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  H 1000 → 1.8E¯4 | -70% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
oh, so using ⍤0 instead of ¨ only sped it up by a tiny bit
1:57 PM
Right, because they are the same under the covers, in the general case.
Btw, I left out my fun solution as it is terrible:
      cmpx'A 1000' '{⌽↑,\⍵⍴''⎕''}1000'
  A 1000          → 5.9E¯4 |      0%
  {⌽↑,\⍵⍴'⎕'}1000 → 9.1E¯2 | +15142% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
OK, that'll be enough for today. See you next week for 2022-6: Pyramid Scheme!
@Adám not seeing how at the moment, any hints?
2:42 PM
@Adám how about reversing the input list rather than the computed matrix?
 
6 hours later…
8:36 PM
Hi everyone, I don't know if this is the right place to ask, so if it isn't please redirect me :)

I'm very much a newcomer to this language, so I'm starting out by trying to solve simple problems: right now I'm trying to write a function that computes the element-wise sum of two vectors when both elements are non zero, and returns 0 otherwise. For example:

¯1 1 1 f 0 1 ¯2

yields 0 2 ¯1

Because I'm currently struggling with trains, I tried to write a tacit function to perform this operation, and I came up with this abomination:

« first day (2494 days earlier)      last day (321 days later) »