fiR_OOPS=: (0:`((>:@(i.{.)}.[) $: }.@])@.(e.~{.))`1:@.(''-:])"1
fiR_ES=: +./@((*. 1 |.!.0 +./\.)/@(=/ |:)~)
fiR_BO=: (('_',~"1 [)((>:@(i."1 {.) |.!.'' "_1 [) $: }.@])`(' ' ~:
{."1@[)@.(0 = #@]) ])
        NB. Guinns approach tacitly with rank _

Performance heavily depends on number  and length of strings.
   AA=: data 20 3e3
   BB=: data 1e3

   ts 'AA fiR_OOPS BB'  NB. Clear winner in this case
0.032740055 5488000

   ts 'AA fiR_ES BB'
0.26523284 67438720

   ts 'AA fiR_BO BB'
0.12177118 2.277536e8

   AA=: data 2000 3e1
   BB=: data 1e1

   ts 'AA fiR_OOPS BB'  NB. Winner in product of time and space
0.029594062 31744

   ts 'AA fiR_ES BB'
0.0026858734 1378432

   ts 'AA fiR_BO BB'
0.0027664029 2504704

So overall fiR_OOPS gives the best performance.
 fiR_ES is the most elegant, IMO.


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Ewart Shaw
> Verzonden: zaterdag 20 augustus 2011 11:37
> Aan: [email protected]
> Onderwerp: [Jprogramming] Search for ordered letters within lines of
matrix
> 
> Sorry all - my previous findinRows_NEW fails when the last match occurs
> between the final characters of x and y.  Something like the following is
ok
>    findinRows_OOPS=: (0:`((>:@(i.{.)}.[) $: }.@])@.(e.~{.))`1:@.(''-:])"1
and
> very fast.  I hope it can be simplified to remove the "hidden agenda".
> 
> --
> J.E.H.Shaw   [Ewart Shaw]      [email protected]    TEL: +44 2476 523069
>  Department of Statistics,  University of Warwick,  Coventry CV4 7AL,  UK
>  http://www.warwick.ac.uk/statsdept    http://www.facebook.com/ewart.sh
> aw
> 3  ((4&({*.(=+/))++/=3:)@([:,/0&,^:(i.3)@|:"2^:2))&.>@]^:(i.@[)  <#:3 6 2
> ----------------------------------------------------------------------
> 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