« first day (2141 days earlier)      last day (506 days later) » 

1:38 AM
Is it possible to run APL code without saving or printing anything?
I have a very hacky solution for AoC day 5 that's basically

{delete ⍵ , copy ⍵} ¨ moves

where delete and copy edit an array in place.
It works, but produces a huge (and useless) nested array that crashes on larger datasets.
I need "run these functions for every value in this array and discard the result".
 
 
2 hours later…
3:23 AM
@Lapwing482 Do an assign at the last line of dfns, e.g. {_←delete ⍵ ⋄ _←copy ⍵}¨moves. This would cause the result to be "shy" and APL will discard the result unless you have a context that requires a result. And as long as there is not such context, no extra cost for ¨ to collect result.
or, just use a tradfns that has no return value.
And if you see other peoples answer, they would just use recursion or reduce to stay functional.
And if you do {_←delete ⍵ ⋄ _←copy ⍵ ⋄ } it is the same to a tradfns without return value.
 
 
2 hours later…
5:10 AM
done, very hardwired answer for day6
Part 1: 3+⍸1↓{4=≢∪⍵~' '}⌺4⊢data, Part 2: 13+⍸6↓{14=≢∪⍵~' '}⌺14⊢data
To golf a bit, they are 3+⊃⍸4=≢¨4∪/data and 13+⊃⍸14=≢¨14∪/data
 
5:25 AM
@Lapwing482 In addition to LdBeth's answer, {} will ignore its argument and return nothing.
 
I had 3+⊃⍸1↓{4=≢∪⍵}⌺4⊢d←⊃⊃⎕NGET'd/6'1⋄14+⊃⍸7↓{14=≢∪⍵}⌺14⊢d
 
@xpqz You counted wrong number of "incomplete" blocks when guessing the solution for part 2, that is 6 instead of 7 but you offset that with 14 so the answer is correct anyway. :D I knew it because I did the same thing.
 
5:43 AM
Heh. Hacking too fast to think properly. Should have gone the windowed unique reduction route like you did...
 
6:11 AM
 
6:34 AM
ChatGPT gave a perfect Py solution, btw, but a broken APL solution.
 
7:00 AM
I'm solving the 7th problem from the 2013 apl solving competition. My non-tacit solution is {((⌈¨⍵)≠⍵)/⍵}. Now I'm trying to make it tacit. I got it down to {((⌈¨≠⊢)⍵)/⍵}. What confuses me is that / is an operator and not a function (If / was a function, I think I knew how to make it tacit). How would I go about making the whole expression tacit?
 
7:32 AM
@andrew Yeah, that is a known issue which you can fix by writing ⊢⍤/ instead of /
 
 
4 hours later…
11:09 AM
My mind immediately jumped to and completely forgot about n-wise reduce. Also missed an opportunity to use :(
4 14{1-⍨⍺+⊃⍸⍺=≢⍤∪⍤1⊢(⌊2÷⍨⍺-1)(-⍤⊣↓↓)⊢⌺⍺⊢⍵}¨⊃⎕NGET'input.txt'1
↓
4 14{1-⍨⍺+⍺⍳⍨≢⍤∪⍤1⊢(⌊2÷⍨⍺-1)(-⍤⊣↓↓)⊢⌺⍺⊢⍵}¨⊃⎕NGET'input.txt'1
↓
4 14(1-⍨⊣+⊣⍳⍨∘(≢¨)∪/)¨⊃⎕NGET'input.txt'1
@Adám Ah I see, that makes sense.
 
@cowile Hi there. interested in APL?
 
12:12 PM
@Adám Thanks! I now got a fully tacit solution (⌈¨≠⊢)(⊢⍤/)⊢ :) I now wonder, if it is possible to simplify this expression? I guess you can also write it as a two train, and for that to work you have to use ⍨ somewhere, but I couldn't get it to work. Am I on the right path to simplify this expression?
 
12:33 PM
@andrew is a scalar function, so you never need ¨. You could write (⌈≠⊢) as ≠∘⌈⍨ but in Dyalog 20.0 it will be possible to write ⌈⍛≠⍛/
 
 
2 hours later…
2:59 PM
Just finished day 4. Took me a lot of time, especially caused by making errors with the correct rank and selections inside an array.
So I used to many ↑ ↓ and ⊃ to correct it I think
 
3:10 PM
is there any other way to split a string in half other than reshape -> split?
 
3:21 PM
you can use take and drop - something like {⍵(↑,⍥⊂↓)⍨2÷⍨≢⍵}'abcdef' works
with floor or ceiling depending which end you want the extra characters for odd length strings
 
3:37 PM
its guaranteed to be even length
 
@Seggan ⊢⊂⍨≢⍴1↑⍨≢÷2⍨
@SilasPoulson Tacit: ⊢(↑,⍥⊂↓)⍨2÷⍨≢
@Seggan ↓⊢⍴⍨2,≢÷2⍨ isn't so bad.
However, I hope we'll have ↓2 .5⍴⊢ one day.
 
yeah i got {↓⍵⍴⍨2(2÷⍨≢⍵)}
not too good at tacit so i only use it if its very short
 
my solution for day 4
 move←↑{(⊃⍵)/⊃⌽⍵}¨⎕VFI¨10↓⊃⎕NGET'input05.txt' 1
 s←↑8↑⊃⎕NGET'input05.txt' 1 ⋄ s←' '(≠⊆⊢)¨↓⍉s[;2+4×1-⍨⍳9]
 {(n f t)←⍵ ⋄ s[f]←⊂⊂n↓c←∊s[f] ⋄ s[t]←⊂⊂(⌽n↑c),∊s[t]}¨↓move
and there are all those ugly ⊂⊂⊂'s
 
@Richard {(⊃⍵)/⊃⌽⍵} is ⊃⊢⍤//
 
3:53 PM
@Adám can you explain that?
 
You want the function / between the first and second (there are only two) values, so you can reduce using ⊢⍤/ (as ⊢⍤ forces / to be a function). However, reduction reduces (!) the rank from 1 to 0 by enclosing, so you need to disclose.
 
hmm im doing day 4 rn, signum is very useful for counting 0s :D
+/~×
 
Or 0+.= or simply +/0=
 
:facepalm:
 
@Adám thank you.
 
3:57 PM
why did i not see such a logical solution
 
Fun ones: ≢0∩⍨ and ≢⍸0=
 
yeah i prefer the simplest to understand one :P
 
I'd say that's +/0=
 
agree
 
4:22 PM
Thanks @Adám - figured would be something like that, but didn't quite think enough to tacitify
 
Day 4
+/0={≢¨~/{⍵[⍋≢¨⍵]}{(⊃⍵)+0,⍳-/⌽⍵}¨⍵}¨data
---
+/{0<≢¨∩/{(⊃⍵)+0,⍳-/⌽⍵}¨⍵}¨data
 
4:52 PM
How do I treat each column of a matrix as vector? I want apply ⍋⍒ to each 'column' of a matrix? So that it returns a vector of the 'y' coordinate of the largest number on each column
 
@PuercoPop ↓⍉
 
@PuercoPop Use rank . ⍉(⊃∘⍋∘⍒)⍤1⍉⊢matrix for example
 
That left-hand doesn't do anything, does it?
 
Well yes it is a no-op if there is but I'm not sure if @PuercoPop wants (⊃∘⍋∘⍒) or just (⍋∘⍒)
 
It seem the description "a vector of the 'y' coordinate of the largest number on each column" contradicts the code ⍋⍒.
 
4:59 PM
isnt there a way to do it with reduce first as well?
 
Yes, ⊃∘⍒¨,⌿
 
Where ,⌿ effectively same to ↓⍉ here.
 
Indeed. It is probably more space-efficient (and thus faster) to stay flat, but if you go the nested route, ,⌿ at least avoids a complete shuffle of the data that requires.
Meh, ↓⍉ is much faster:
      a←?100 100⍴0
      ]runtime -c ,⌿a ↓⍉a

  ,⌿a → 1.5E¯3 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  ↓⍉a → 2.1E¯5 | -99% ⎕
 
I really hope one day ⍉⌽⊖ only copies a "header" on how to traverse the data, instead of copy the whole array. Or maybe it is already implemented in Dyalog
 
Apparently, the grading completely drowns out the re-structuring cost:
  ⊃∘⍒¨↓⍉a → 4.4E¯4 |  0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  ⊃∘⍒⍤1⍉a → 4.5E¯4 | +3% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
@LdBeth Thunks can possibly provide some of that for some operations, but in general, it just forces the a slow-down in access down the line.
That said, ⊃⌽ is optimised:
  ⊃⌽a  → 5.0E¯8 |      0%
  ⊃⊢⌽a → 8.8E¯6 | +17584% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
5:07 PM
@LdBeth I wanted ⊃∘⍋∘⍒
 
Yep grade does not gain much from parallelization.
 
You don't need parens or there.
 
Then actually the can be ommited
 
@PuercoPop That computes the location where the first element will end up if sorted descending. Is that really what you want, rather than the location of the largest element?
Compare: ⋄ ⊃⍒30 50 40 20 10 ⋄ ⊃⍋⍒30 50 40 20 10
 
g←⍉↑(0 0 0 1 0 2)(2 3 1 0 0 0)(0 0 0 0 1 0)
(⊃∘⍋∘⍒)⍤1⍉⊢g ⍝ This doesn't return what I expect
⊃¨⍒¨↓⍉g ⍝ This returns the values I expect, 6 2 5. Does using composition means its more performant as it does the work in one pass?
 
5:11 PM
@Adám
2
3
 
Composition actually adds some overhead
 
Grading is so much more expensive than the structural manipulation that it doesn't matter.
 
⋄ ⍋⍒30 50 40 20 10
 
@LdBeth 3 1 2 4 5
 
APLcart said ⍋⍒ is Descending cardinal numbers
 
5:16 PM
@PuercoPop You gain much more by switching to a more efficient algorithm:
      g←⍉↑{500?1e6}¨⍳500
      ]runtime -c ⊃¨⍒¨↓⍉g ⊃∘⍒¨↓⍉g ⊃∘⍒⍤1⍉g (⊢⍳⌈/)¨↓⍉g

  ⊃¨⍒¨↓⍉g    → 1.2E¯2 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  ⊃∘⍒¨↓⍉g    → 1.2E¯2 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  ⊃∘⍒⍤1⍉g    → 1.3E¯2 |  +3% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  (⊢⍳⌈/)¨↓⍉g → 4.7E¯4 | -97% ⎕
@LdBeth Yes. The position that each element will end up in when sorting descending.
 
Thanks, so I guess the first step is always to turn the matrix into a nested array of columns like Richa suggested.
 
Or transpose and use ⍤1 — it doesn't matter.
 
      ]runtime -c +¨↓⍉g +¨↓⍉g +⍤1⍉g

  +¨↓⍉g → 2.8E¯4 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  +¨↓⍉g → 2.8E¯4 |  -2% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
* +⍤1⍉g → 1.6E¯4 | -45% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
Not sure what you're trying to say here.
 
@PuercoPop If the functional can be parallelized, use is better. These includes +-÷×|*⍟⌈⌊<≤=≥>≠∧∨⍱⍲~○
 
5:27 PM
But you might also want to reconsider your data structure. You should structure your data so that you don't need to transpose.
 
Well no never mind on my argument that use . it is only good for saving space, does not save much time.
 
6:27 PM
@Adám yeah, maybe trying to force a matrix to represent a list of stacks was the wrong choice, will reconsider my approach
 
@PuercoPop Matrices are conceptually lists of rows, so using a matrix for a list of stacks is fine, but keep the stacks as rows, not columns.
 
 
3 hours later…
9:57 PM
Why does this:

{0}1 2 3

return 0 1 2 3 and not just 0?
From my (very beginner) understanding of APL, the 1 2 3 array should be passed as an argument to function {0}, which ignores it and returns 0 as the line output.
What's happening instead?
 
@Lapwing482 Because you're using NARS2000 or GNU APL.
 
GNU APL
 
They both "support" niladic dfns (lambdas). Niladic "functions" are executed immediately, and are then replaced by their result in the surrounding expression.
If you want a function to accept an argument but ignore it then {0⊣⍵} should do the trick.
If you want a function to accept two arguments but ignore them then {0⊣⍺⍵} should do the trick,
Dyalog, dzaima, and ngn dfns are always ambivalent, never niladic.
 
@Adám works great, thanks!
 
 
1 hour later…
11:08 PM
> The matrix representation is better for dense graphs (who didn't date whom)

Joke intended. D:
 

« first day (2141 days earlier)      last day (506 days later) »