« first day (816 days earlier)      last day (85 days later) » 

7:00 PM
As part of this problem, I've been looking for a nice J phrase to remove all the letters in word from another repeat, without ignoring repeats. That is removing THERE from SEVENTEEN for example should result in SVNEEN. This means set difference can't be used. My current solution is labored: <"0@[ (<^:3@i. { [) ::[~&.>/@, <@].
Try it online!. Can this be much improved? cc/ @ngn
 
ngn
7:22 PM
@Jonah is there a tool in j to show how this parses?
 
@ngn I added it here: Try it online!
 
ngn
@Jonah thanks
 
Fundamentally, it's just a reduction on the word we're removing letters from.
And triple box is used to filter "everything except". I think the rest should make sense.
 
ngn
i'm a j noob. i have to look everything up in the docs :)
 
oh i didn't realize. i assumed you were an expert because you've helped recently with some golfs and noticed things even experienced J-ers missed.
 
ngn
7:38 PM
what i've been able to decode so far: <"0@[ is box each x
<@]. is box y
concatenate those (,) and then comes the reduction
it's a reduction of something large under (&.) unboxing (>)
@ngn oops, <@] without the .
~ reverses the arguments. so far this pattern of using reduction looks familiar from apl
 
Yes I'd guess so. Let me add a couple intermediate steps to clarify. Although I think I may have found another approach (still seeing if it leads to less code though...)
So in the general pattern, all the items on the left (in this case, the individual letters) are what we're reducing, and the item on the right is the result. J's right to left evaluation naturally produces the reduction, so that the "reduction" operation is just a consequence of the "Insert" adverb /
 
ngn
@Jonah is the triple boxing something special that { understands?
 
@ngn Exactly.
{ is probably the single most complicated verb in J, and that box within a box pattern is how you achieve "complement of". Nuvoc has better examples than the dictionary for that, if you're ever curious to explore more: code.jsoftware.com/wiki/Vocabulary/curlylf#dyadic
Also, Dan Bron's essay on its history and motivation and differences from APL's [] indexing operator is required reading.
 
ngn
7:57 PM
so (<<<indices){vec means "remove"
 
@ngn Yep.
 
ngn
@Jonah and if i. doesn't find one of the y's chars in x, it will return the length of y for that char
and the :: will apply its right operand
"adverse"?? - that's a "try-catch" to me :)
 
@ngn exactly, that's try catch. and it will return [ which is the left arg, but since we're using ~ to modify the whole thing the left arg is the right arg visually, ie, the result on the right :)
 
ngn
so, even if a single letter is not found, the "catch" part will be triggered?
 
*only when a single letter is not found
 
ngn
8:04 PM
ah... i see. i.'s left arg is always a 1-element vector
 
@ngn yes
 
ngn
or boxed scalar... whatever
ok, i think i got it now, with your help :)
hm, it seems the space between ) and :: is required
 
@ngn yeah it is, not entirely sure why
my real question is if there's a completely different high-level approach that's more suited to "array thinking." reductions are really rather procedural things... but i still haven't found any other approach that works here.
 
ngn
@Jonah certainly there are other approaches, but it's not so clear which has the greatest chance of being the shortest
for instance, i was thinking of using the key operator (i'm sure there must be one in j)
 
@ngn Indeed there is /. -- I fiddled with that a bit but didn't find anything better going that route. Which ofc doesn't mean there isn't something better that route...
 
ngn
8:16 PM
⎕←'THERE'{n←≢⍺⋄(∪⍺,⍵)/⍨0⌈{+/¯1*⍵<n}⌸⍺,⍵}'SEVENTEEN' ⊣ ⎕io←0
 
@ngn
EESVNN
 
ngn
i don't know if this could be translated efficiently into j
 
@ngn Can you describe in words what it's doing? My APL is super noob-ish.
 
my attempt at using key (if i've understood the question right)
 
ngn
@Jonah {}⌸A groups the elements of A and applies the {} to each group - ⍺ is the element, ⍵ is the list of indices where it occurs. the result from ⌸ is mixed
@dzaima that's shorter than mine and looks more promising
 
@dzaima do you think the translation of that in J ends up being shorter than my original attempt?
 
@Jonah I sadly don't know much about j either
 
I'm attempting to translate. Are you using letter counts in the APL solution?
 
ngn
here's another idea: ,\∩¨⊢
when applied to a string, this train replaces the second a with aa, the third a with aaa etc
so we can apply the train to both arguments and use "without"
then "first each" should restore the original letters
 
@Jonah the main thing still is over 'SEVENTEEN', which then returns the positions of each letter type to remove
 
8:32 PM
@ngn ohhhhh... that seems promising
 
ngn
⎕←⊃¨⊃~/(,\∩¨⊢)¨⌽'THERE' 'SEVENTEEN'
 
@ngn
SVNEEN
 
ngn
@Jonah does j have a ?
 
@ngn What is the name of that operator? In any case, I think this approach can be achieved in J one way or another
 
ngn
@Jonah dyalog call it intersection
 
8:43 PM
So I've got: (,. <@#"0 1~ (#\ +/@{."0 1 ])@e.) 'SEVENTEEN' But I can do much better than that.
Need to take off for a bit. Will report back if I have a good translation later. Thank you both for your help.
 
9:02 PM
Ok got it [: {.&> -.&(((e. <@# [) {:)\): Try it online!
The significant chars there could be golfed down a little, but that's basically the J translation. Intersect is J is built up from other primitives: e. # [
This approach def improves on my original. Thanks again.
 

« first day (816 days earlier)      last day (85 days later) »