« first day (428 days earlier)      last day (2520 days later) » 

14:10
Yesterday the funeral of Phil Goacher, one of the founding members of Dyadic Systems and Dyalog APL, took place ... see Geoff's blog post for some personal memories https://www.dyalog.com/blog/2018/03/phil-goacher-05-11-40-09-03-18/
@Feeds :( rip
Ven
Ven
:(
15:04
With all the Easter chicks popping up in our Twitter feed we started to wonder about the age old conundrum ... and typically tried to solve it using APL http://tryapl.org/?a=%27The%20%27%2C%28%28%3F2%29%u2283%27chicken%27%20%27egg%27%29%2C%27%20came%20first%27&run
 
1 hour later…
16:08
@Feeds gold.
16:33
@Adám if I need to find one instance of each letter in the string 'STRING' on another string/vector passed as argument, what should I use? I've tried using but it doesn't seem to work the way I thought it did
@J.Sallé ?
⍞←⎕A⍳'STRING'
@Adám 19 20 18 9 14 7
@Adám that could work. it gives me the indices, right?
@J.Sallé Yes. Do you want a Boolean with true at those positions instead?
That would be better, yes
16:36
⍞←⎕A∊'STRING'
@Adám 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0
Ah, it's epsilon without the underbar >.>
@J.Sallé Yes, that's just plain membership. You can also go with a Boolean table:
⎕←'STRING'∘.=⎕A
@Adám
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Oh, that might actually be better
16:38
@J.Sallé As you can see, ∊ ≡ (∨/∘.=)
@Adám That table trick solved a bunch of problems actually
Since a simple +/ now gives me the total number of appearances for each letter
@Adám can you help me golf this? I feel it has some unnecessary parenthesis: 1 5 10 25(⊢,(+/×))+/'PNDQ'∘.=<arg>
The goal is to count the number of each of 'PNDQ', multiply by their values and append to the end of the vector
The result should look like 3 4 5 6 <sum of those numbers×their values>
@J.Sallé Well, (+/×) is just +.× (on scalars and vectors anyway)
Ah, I didn't know that one
@J.Sallé So 'QUANDUPPUM' should give 2 1 1 1 42?
@Adám actually the strings are only made of Ps, Ns, Ds and Qs (the american coins, for this challenge)
I'll need to treat the lack of zeroes though for the test cases with only 1 of those
That might be a problem though
I think I need to pad the table ∘.= generates with 0s
16:57
@J.Sallé Why? What's wrong with your formula?
⍞←1 5 10 25(⊢,+.×)+/'PNDQ'∘.='QQQQ'
@Adám 0 0 0 4 100
⍞←1 5 10 25(⊢,+.×)+/'PNDQ'∘.='Q'
@J.Sallé 1 41
@J.Sallé Nope, just faulty input:
⍞←1 5 10 25(⊢,+.×)+/'PNDQ'∘.=,'Q'
16:58
@Adám 0 0 0 1 25
Aaaaaaaaah
Well that was easy
@J.Sallé Just require that input is a vector.
@Adám Yup, now it works perfectly. Thanks! I think this is the first time I actually managed to do the whole thing tacitly without making a dfn first.
@J.Sallé Nice. At some point, tacit just clicks, and you start seeing the structure.
Huh, I think that's exactly how I'd describe it.
17:01
@J.Sallé Btw, how are you going to present your solution, as one long train?
@J.Sallé Nope, that's a snippet, not a function or program.
D:
What do?
I can't assign that to a name, can I?
@J.Sallé Well, now you have to golf to keep the byte count. I'll guide you.
The problem is with +/ which has to be applied monadically.
Oh geez, okay
@Adám I remember we can use the unary base thing to go around that?
17:04
@J.Sallé Ah, very good!
@J.Sallé But the problem is that 1⊥ sums columns, and you need the rows summed. Can you think of a solution?
Gimme a sec
@Adám gotta transpose it first. 1⊥⍉
@J.Sallé Yes, but that will cost you a byte. There's another way (although you'll have to require that the input is a vector, which is allowed per OP).
@Adám A vector as in 'P' 'Q' 'N'...?
If I take input like that I seem to not need the last , nor the transpose.
@J.Sallé Well, that's the same as 'PQN'. It just means that 'Q' isn't a valid input, but ,'Q' or ∊'Q' or 1⍴'Q' are, and so is ⎕JSON'"Q"'
@J.Sallé Uh, you do need to transpose for multi-char input. Well, except you can avoid that. Do you want me to tell you how?
@Adám Just a sec, I tried something on the REPL and it seemed to work?
⍞←1⊥'PNDQ'∘.='PQND'
17:11
@J.Sallé 1 1 1 1
but then the 'Q' test case breaks
I see your point
@Adám okay tell me
@J.Sallé Notice that = is commutative.
Indeed
⍞←1⊥'PNDQ',.='D'
@J.Sallé  0 0 1 0
And ∘. puts the left arg vertically, and the right arg horizontally:
⎕←'PNDQ'{(' ',⍺),⍵⍪⍺∘.=⍵}'PNNDNNQPDNPQND'
17:13
@Adám
  P N N D N N Q P D N P Q N D
P 1 0 0 0 0 0 0 1 0 0 1 0 0 0
N 0 1 1 0 1 1 0 0 0 1 0 0 1 0
D 0 0 0 1 0 0 0 0 1 0 0 0 0 1
Q 0 0 0 0 0 0 1 0 0 0 0 1 0 0
So swapping the arguments of ∘.f where f is commutative is the same as ⍉∘.f:
Witchcraft!
⎕←'PNDQ'{(' ',⍺),⍵⍪⍺∘.=⍵}⍨'PNNDNNQPDNPQND'
@Adám
  P N D Q
P 1 0 0 0
N 0 1 0 0
N 0 1 0 0
D 0 0 1 0
N 0 1 0 0
N 0 1 0 0
Q 0 0 0 1
P 1 0 0 0
D 0 0 1 0
N 0 1 0 0
P 1 0 0 0
Q 0 0 0 1
N 0 1 0 0
D 0 0 1 0
And now you can safely sum the columns:
⍞←1⊥'PNNDNNQPDNPQND'∘.='PNDQ'
17:15
@Adám 3 6 3 2
I see it, but how do I swap the arguments? A in there raises a syntax error
@J.Sallé Ah, because a train cannot have a constant on the far right, but we can just glue the function ∘.= together with the constant:
⍞←(1⊥∘.=∘'PNDQ) 'PNNDNNQPDNPQND'
@Adám
Ah, another then
⍞←(1⊥∘.=∘'PNDQ') 'PNNDNNQPDNPQND '
17:17
@Adám 3 6 3 2
@J.Sallé Yes, and that's safe because operators are left-associative, so ∘.= becomes a single function first, and only then the right argument gets composed with that.
I'll still need that , though for the single letter test cases
⍞←1 5 10 25(⊢,+.×)(1⊥∘.=∘'PNDQ'),'P'
@J.Sallé 1 0 0 0 1
And I still can't seem to be able assign that to a name >.> what am I doing wrong?
@J.Sallé Yes, but you don't need the rightmost paren now that you use 1⊥.
@J.Sallé TIO link?
@J.Sallé You have a stray , on the far right!
@Adám yeah but don't I need that?
⍞←1 5 10 25(⊢,+.×)1⊥∘.=∘'PNDQ'⊢'P'
@J.Sallé 1 41
@J.Sallé No, you'l require the input to be a vector. That'll be the user's responsibility to provide.
Aaaaaaaaaaah, I forgot that
17:23
@J.Sallé Well, you didn't supply a vector. User error.
@J.Sallé Yes, exactly. Here's the entire test suite.
@Adám Nice! Thanks a bunch, that was enlightening.
I think 1⊥ is my new best friend.
@J.Sallé :-D

« first day (428 days earlier)      last day (2520 days later) »