Hmm...

A bugfixed version of my previous implementation (it broke when x -. y
was empty) performs approximately the same, for me:

cle=: ,~ #~ i.@#@,~ e. [: ; (2*#/.~@]) (}.&.>~ #@[ {. ])~ (]i.,~) </. i.@#@,~

I say approximately, because timing variations mean that when I test
on the same data, sometimes it's faster and sometimes it's slower than

   oc=: i.~ (] - {) /:@/:
   cless =: [ #~ oc@:[ >: (i.~~.) { (#/.~,0:)@]

That said, Boss's implementation is clearly more concise...

Thanks,

-- 
Raul



On Mon, Jan 18, 2016 at 12:17 PM, Marshall Lochbaum
<[email protected]> wrote:
> That's a very cool solution, and much quicker than the one based on
> progressive index-of. Instead of taking the occurrence count of both x
> and y, it just takes the count for x and compares it to the total number
> of occurrences in y, given by (#/.~).
>
> Here's a comparison of the two methods. It turns out in the version
> based on progressive index-of, the desired verb can be obtained just
> from replacing (i.) with (-.) and then using the first column of the
> result to select from x, so I've used that version.
>
>    NB. Shared verb for occurrence count
>    oc=: i.~ (] - {) /:@/:
>    NB. Simplified form of what Roger and I posted
>    cless1 =: [ {~ [: {."1 #@[ ({. -.&(,.oc) }.) [ i. ,
>    NB. Tacitized R.E. Boss solution
>    cless2 =: [ #~ oc@:[ >: (i.~~.) { (#/.~,0:)@]
>
>    NB. test data
>    'a b' =. 500 ({.;~}.) +&(1e5 ?@$ 26)&.(a.&i.) 'a'
>    10 (6!:2) 'a cless1 b'
> 0.0178952
>    10 (6!:2) 'a cless2 b'
> 0.0063745
>    a (cless1 -: cless2) b
> 1
>
> To summarize, here's the fastest solution so far:
>    oc=: i.~ (] - {) /:@/:
>    cless =: [ #~ oc@:[ >: (i.~~.) { (#/.~,0:)@]
>
> Marshall
>
> On Mon, Jan 18, 2016 at 03:49:46PM +0000, R.E. Boss wrote:
>> I'm getting old, but still remember my solution, improved by Hui:
>>
>> http://www.jsoftware.com/pipermail/general/2004-May/017503.html
>>
>>    'abcabbe' strikeb2 'babe'
>> cab
>>
>> Curious how it performs compared to the other solutions.
>>
>>
>> R.E. Boss
>>
>>
>> > -----Original Message-----
>> > From: Programming [mailto:[email protected]]
>> > On Behalf Of June Kim (???)
>> > Sent: maandag 18 januari 2016 5:19
>> > To: Programming forum <[email protected]>
>> > Subject: [Jprogramming] A Different Less?
>> >
>> > Hello
>> >
>> > I am looking for a verb(cless) that does something similar to Less(-.) but
>> > counting the elimination, for example:
>> >
>> >    'abcabbe' -. 'abbe'
>> >
>> > c
>> >
>> >    'abcabbe' cless 'babe'  NB. get rid of y letters counting the 
>> > occurrences
>> >
>> > 'cab'
>> >
>> >
>> > It is easier to define such a verb recursively: 'abcabbe' cless 'babe'
>> > equald to 'e' cless~ 'b' cless~ 'a' cless~ 'b' cless~ 'abcabbe'
>> >
>> >
>> > I think recursive definition isn't a usual J-ic approach.
>> >
>> >
>> > How would you implement such a verb elegantly(with which I mean short)?
>> >
>> >
>> > June
>> > ----------------------------------------------------------------------
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to