On Nov 7, 2007 11:29 PM, Arie Groeneveld <[EMAIL PROTECTED]> wrote:
> but there's a flaw:
>
>    7 0 pattern dat
>
>    7 0 p2 dat
> |length error: p2
> |   7 0     p2 dat

Oops. You are right, there is a flaw... Thank you!
So here is my new fixed version then :)

p4=:( (#~ (+:_1|.]) @ (=1|.<:) ) @ I. @ E.~$/ )~

It seems to be slightly better in terms of performance..

   6!:2 '5 0 pattern in'
0.0161652
   6!:2 '5 0 patRM17 in'
0.0152835
   6!:2 '5 0 pat172 in'
0.0297362
   6!:2 '5 0 p4 in'
0.00920815

 ..and I might be wrong, but even with "bad" short patterns (thank you
for pointing me at this issue with the length of the pattern
differences, by the way!)

   6!:2 '1 0 pattern in'
0.0169181
   6!:2 '1 0 patRM17 in'
0.0168586
   6!:2 '1 0 pat172 in'
0.0283919
   6!:2 '1 0 p4 in'
0.0156168

NB. the running time greatly depends on the data itself - with
different "in"s you'll get slightly different results..

PS But I am sure there should be some better, shorter and faster
solution anyway ;)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to