« first day (2480 days earlier)      last day (167 days later) » 

8:03 AM
0
Q: Dyalog APL: Check if a field exists in JSON?

конструкторThe task is to check if there is an "s" field in the JSON, I've tried to do this as follows: ⍝ Example JSON I'm working with JSON ← '{"e":"depthUpdate","E":1699599166770,"s":"BTCUSDT","U":40239636237,"u":40239636314,"b":[["36651.78000000","9.81839000"],["36584.34000000","0.00000000"],["3654...

 
 
5 hours later…
1:00 PM
Welcome to APL Quest 2022-3! Today's quest is Uniquely Qualified:
> Write a function that:
• takes right and left arguments that are arrays of arbitrary rank, depth, and value.
• returns a vector of all elements that appear in either of the two argument arrays but not in both. The order of elements in the result is not significant.
 
(~,~⍨)⍥,
 
Huh, I didn't think of that. Nice.
 
And I couldnt find your 7 chars solution...
 
Hint: We want all the elements from both, except the shared ones.
 
(∪~,)⍥,
 
1:03 PM
Did you test that‽
 
no :)
 
and , are almost the same, save for duplicates, so there's nothing left.
 
oh, I meant (∩~,)⍥,
will test it
 
is a subset of , (and ), so again, nothing left.
Hint: Remember that ~ is "without", so "X without Y".
 
no...
 
1:08 PM
So, going back to my original hint, "the elements from both" would be , or and the shared ones would be
 
yes, so all elements (,) without the shared ones (∩)
 
Right.
 
,~∩
 
Right, ⍥,
 
ah, now I see what I did wrong.
,~∩ instead of ∩~,
 
1:10 PM
Exactly.
 
I like how ∪~∩ uses all the set functions. Richard's ~,~⍨ is nice too.
 
yes, imo (∪~∩)⍥, looks cooler than (,~∩)⍥, — not sure which is faster.
      x←1E3?1E4
      y←1E3?1E4
      cmpx'x(∪~∩)y' 'x(,~∩)y' 'x(~,~⍨)y'
  x(∪~∩)y  → 8.2E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  x(,~∩)y  → 6.0E¯6 | -28% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  x(~,~⍨)y → 5.5E¯6 | -34% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
These two share very few elements, of course.
      x←1E3?2E3
      y←1E3?2E3
      cmpx'x(∪~∩)y' 'x(,~∩)y' 'x(~,~⍨)y'
  x(∪~∩)y  → 8.0E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  x(,~∩)y  → 8.6E¯6 |  +8% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  x(~,~⍨)y → 5.4E¯6 | -33% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
These share about half of their elements (the former was a tenth).
So, I think we can conclude that Richard's original is fastest generally.
The fastest of the other two depends on the data.
 
how nice all these look :) A nice example of how powerfull APL can be. And at least for me, very good understandable. If you read them out loud it is exactly the expected solution.
' The joined elements without the common elements'
 
Yes, and I think it is also one of the best examples of a dyadic train. Writing {(⍺∪⍵)~(⍺∩⍵)} really doesn't provide much extra clarity.
 
yes indeed
Or 'the left elements without the right elements, joined with, the right elements without the left ones'
but yours is even more clear
 
1:21 PM
Can also be read as "the elements unique to the left, followed by the elements unique to the right".
 
yes
 
{(⍺∪⍵)~(⍺∩⍵)} vs (∪~∩) was also the one that made forks "click" for John Daintree, when he was preparing his Dyalog '23 presentation on token-by-token tracing.
As he traced through both, he saw the current-token indicator jump in exactly the same pattern for both, thus realising that forks aren't as out-of-normal-order as he previously believed.
 
:)
 
Indeed, he quickly saw {(⍺⍵)(⍺⍵)} as just noise, obscuring the actual data processing that's happening.
∪~∩ boils down the algorithm to its essence: The union without the intersection.
 
exactly. I noted that the further we get into the Quest, the more tacit notation becomes valuable. Was that done on purpose, or am I just getting more used to it?
I am not translating it anymore for the easy problems, and starting in tacit directly
 
1:28 PM
Not directly on purpose, since each problemset is developed in isolation. However, as we've added more tacit features over the years, we have on occasion tried to include problems that lend themselves to using the new features.
 
btw, I also made a solution using ⌸ just for fun. But that was much too long and have thrown it away.
 
And about starting directly in tacit: Amazing — you made it! People keep thinking I translate things to tacit for the sake of brevity/obscurity.
@Richard I wonder what the performance looks like.
 
horrible probably :)
 
Well, I'm not sure. All these solutions have in common that they have to do multiple set-operation passes on the data.
I wonder if there's a better way, for example by checking if indices of unique elements appear both before and after the joining point of the combined arrays.
 
@Adám thanks, somewhere your mindset has to be changed again. Like a switch which is turned over without noticing...
 
Ven
1:33 PM
I also tend to start thinking about it in tacit
also to force myself to think in APL, not in a procedural language
 
@Adám thinking about that one
 
      'DYALOG' {c←≢⍺ ⋄ ⊃⊢⍤//↓⍉{(≠/0 1∊c<⍵)⍺}⌸⍺,⍵} 'APL'
DYOGP
 
ow, my ⌸ solution looked quite different. Shouldn't have thrown it away
 
Do you not have session log?
 
Probably on the other computer. I could scroll up indeed
 
1:38 PM
Anyway, this is so far from being competitive in speed, that I won't even bother to optimise it.
 
never mind.
Having more and more fun with it
 
This problem, or APL Quests in general?
 
APl Quests in general
 
OK, then see you next week for In the Long One…
 
sometimes I think I am not progressing at all, but then unexpected you make e little jump
Next week!
 
Ven
1:43 PM
Mh, aplcart has no entry for "occurences"
 
You need to spell it with two r's.
 
Ven
duh
I'm dumb.
Mh, seems like what I wanted is {--⌿(2,≢⍵)⍴⍋⍋⍪⍨⍵}
 
2:45 PM
@Adám here's a very slow one: +⌿1∊¨⊂⍤,⍷⍨¨1⍴⍨¨⍳⍤≢
(and here's a decent one: ⌈⌿0,(≢¨)⍤⊆⍨⍤,)
wow, looks like it's too slow for TryAPL to handle
 

« first day (2480 days earlier)      last day (167 days later) »