> From: "Sherlock, Ric" <[EMAIL PROTECTED]>
> 
> ---Roger Hui wrote:
> >    f0=: 4 : '(I.x)> >    f1=: 4 : '((i.#y) e. +/\0,x) <;.1 y'
> >
> >    x=: 1+1e4 [EMAIL PROTECTED] 100
> >    y=: t {~ (+/x) [EMAIL PROTECTED] #t=. 'barack obama'
> >
> >    x (f0 -: f1) y
> > 1
> >    ts=: 6!:2 , 7!:[EMAIL PROTECTED]
> >
> >    ts 'x f0 y'
> > 0.0700156 1.09591e7
> >    ts 'x f1 y'
> > 0.00778395 4.20992e6
> 
> When I saw Brian's solution I wasn't going to post mine - his was so much 
> simpler (BTW I have only used monadic I. to turn a boolean into an index of 
> 1s 
> and hadn't realised what it did with integers). Roger's post prompted me to 
> time 
> mine and the result surprised me.
> 
>    f2=: 4 : '(1 (<:+/\x)} (#y)$0) <;.2 y'
>    x (f1 -: f2) y
> 1
>   50 ts 'x f0 y'
> 0.030942459167 10976256
>   50 ts 'x f1 y'
> 0.0077791269561 4227072
>   50 ts 'x f2 y'
> 0.0060425808308 2654272

For completeness,

   f3=: (,:"0~ 0,+/[EMAIL PROTECTED]:)@[ <;.0 ]
   x (f0 -: f2) y
1

   3 ts 'x f1 y'
0.00764483 4.21952e6
   3 ts 'x f3 y'
0.0122254 5.05888e6


      
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to