[First posting using gmail account, which I hope works better then my
university email!]

Marshall Lochbaum's tacit version of Don Guinn's  findinRows_EX  is
incorrect when
x becomes empty before y, but it's easy to fix & also made to work
with repeated characters in y:
   fiR_NEW=: ((>:@(i.{.)}.[)$:}.@])`(>&#)@.(0=*&#)"1
It is then a clear winner:


NB. fiR = findinRows for brevity
NB. Raul Miller/Marshall Lochbaum  2011-August/023689.html
fiR_ML=: [: *@#@> [: ([ #~ (< {:))&.>/ <@I.@(=/~)

NB. Don Guinn/Marshall Lochbaum  2011-August/023708.html
fiR_EX=:(4 : 0)"1
while. #x do.
  if. ''-:y do. 1 return. end.
  x=.x}.~x i.{.y
  y=.}.y
end.
0
)
fiR_DM=: (([}.~(i.{.))$:}.@])`(''-:])@.(0=*&#)"1
fiR_NEW=: ((>:@(i.{.)}.[)$:}.@])`(>&#)@.(0=*&#)"1

NB. Ewart Shaw  original  2011-August/023690.html (SH)
NB. & following comments by Viktor & Raul (ES)
fiR_SH=: +./@((*. +./\.)/@|:@(=/))
fiR_ES=: +./@((*. 1 |.!.0 +./\.)/@(=/ |:)~)


   NB. Testing
   NB. Viktor Cerovski's test data  2011-August/023696.html
   ]A=: 'CTGGTTGAT','GTAGTCATA','CATGTCTAA','TCGAAAGTT',:'CCGGAGAAG'
CTGGTTGAT
GTAGTCATA
CATGTCTAA
TCGAAAGTT
CCGGAGAAG
   A (fiR_ML; fiR_EX; fiR_DM; fiR_NEW; fiR_SH; fiR_ES) 'TAG'
+---------+---------+---------+---------+---------+---------+
|0 1 0 1 0|0 1 0 1 0|1 1 1 1 0|0 1 0 1 0|0 1 0 1 0|0 1 0 1 0|
+---------+---------+---------+---------+---------+---------+
   A (fiR_ML; fiR_EX; fiR_DM; fiR_NEW; fiR_SH; fiR_ES) 'TAA'
+---------+---------+---------+---------+---------+---------+
|0 1 1 1 0|1 1 1 1 0|1 1 1 1 0|0 1 0 1 0|1 1 1 1 0|0 1 1 1 0|
+---------+---------+---------+---------+---------+---------+
   A (fiR_ML; fiR_EX; fiR_DM; fiR_NEW; fiR_SH; fiR_ES) 'TAAG'
+---------+---------+---------+---------+---------+---------+
|0 0 0 1 0|0 1 0 1 0|1 1 1 1 0|0 0 0 1 0|0 1 0 1 0|0 0 0 1 0|
+---------+---------+---------+---------+---------+---------+

   NB. Raul Miller's test data  2011-August/023698.html
   data=: 'ACGT' {~ 4 ?.@$~ ]
   AA=: data 20 3e3
   BB=: data 1e3
   ts 'AA fiR_ML BB'
0.771007 1.50822e8
   ts 'AA fiR_EX BB'
0.16275 18880
   ts 'AA fiR_NEW BB'   NB. Wow!
0.114482 4.96813e6
   ts 'AA fiR_SH BB'
3.0977 1.34547e8
   ts 'AA fiR_ES BB'
0.533194 6.74377e7
   AA (fiR_NEW -: fiR_ES) BB
1

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

Reply via email to