OK, convinced, Shaws solution doesn't handle equal neighbors well.
But this design flaw is easily repaired (without loss of elegance or
performance):
findinRows_SB=: +./@((*. 1 |.!.0 +./\.)/@|:@(=/))
A=:'CTGGTTGAT','GTAGTCATA','CATGTCTAA','TCGAAAGTT',:'CCGGAGAAG'
A findinRows_SB 'TAA'
0 1 1 1 0
A findinRows_SB 'TAAG'
0 0 0 1 0
findinRows_ML=: [: *@#@> [: ([ #~ (< {:))&.>/ <@I.@(=/~)
A findinRows_ML 'TAA'
0 1 1 1 0
A findinRows_ML 'TAAG'
0 0 0 1 0
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Viktor Cerovski
> Verzonden: vrijdag 19 augustus 2011 15:20
> Aan: [email protected]
> Onderwerp: Re: [Jprogramming] Search for ordered letters within lines of
> matrix
>
>
>
> R.E. Boss wrote:
> >
> > Shaws solution is superior in every respect, more elegant, faster and
> > leaner.
> >
> >
> A=:'CTGGTTGAT','GTAGTCATA','CATGTCTAA','TCGAAAGTT',:'CCGGAGAAG'
> > B=:'TAGT'
> >
> > ts' AA findinRows_ML BB'[AA=: 500 $,:A [BB=:500$B
> > 1.7589716 4.0105395e8
> >
> > ts' AA findinRows_SH BB'
> > 0.13684443 33720960
> >
> > 1.7589716 4.0105395e8 % 0.13684443 33720960
> > 12.853805 11.893314
> >
> > AA (findinRows_ML (-: |:) findinRows_SH) BB
> > 1
> >
> >
> > R.E. Boss
> >
> >
> >> -----Oorspronkelijk bericht-----
> >> Van: [email protected] [mailto:programming-
> >> [email protected]] Namens Viktor Cerovski
> >> Verzonden: vrijdag 19 augustus 2011 14:24
> >> Aan: [email protected]
> >> Onderwerp: Re: [Jprogramming] Search for ordered letters within lines
> >> of matrix
> >>
> >>
> >>
> >> Ric Sherlock wrote:
> >> >
> >> > Update!
> >> > Ewart Shaw sent me this version which looks to be nicer in all
> >> respects.
> >> >
> >> > findinRows=: +./@((*. +./\.)/@|:@(=/))
> >> >
> >> > On Fri, Aug 19, 2011 at 9:28 AM, Ric Sherlock <[email protected]>
> >> wrote:
> >> >> Thanks to everyone for the interesting approaches. I enjoyed
> >> >> dissecting the different thinking processes.
> >> >>
> >> >> As Marshall points out, not all the solutions will work on lists
> >> >> that contain non-unique characters which I think is a desirable
> >> >> characteristic. His development of Raul's approach seems to have
> >> >> the best combination of generality, performance and simplicity.
> >> >>
> >> >> findinRows=: [: *@#@> [: ([ #~ (< {:))&.>/ <@I.@(=/~)
> >> >>
> >> > [...]
> >> >
> >> Shaw's solution is really nice. Let's not forget though that
> >> Marshall's
> > is more
> >> general.
> >>
> >> Straightforward simplification of the later is to replace
> >>
> >> ([ #~ (< {:))
> >>
> >> by
> >>
> >> ((< {:) # [)
> >>
> > [...]
> >
>
> Well, I still think the same, here are examples:
>
> findinrowsM=: [: *@#@> [: ((< {:) # [)&.>/ <@I.@(=/~)
> findinrowS =: +./@((*. +./\.)/@|:@(=/))
>
> ]A=:'CTGGTTGAT','GTAGTCATA','CATGTCTAA','TCGAAAGTT',:'CCGGAGAAG'
> CTGGTTGAT
> GTAGTCATA
> CATGTCTAA
> TCGAAAGTT
> CCGGAGAAG
>
> A findinrowsM 'TAG'
> 0 1 0 1 0 NB. correct
> A findinrowS 'TAG'
> 0 1 0 1 0 NB. correct
>
> A findinrowsM 'TAA'
> 0 1 1 1 0 NB. correct
> A findinrowS 'TAA'
> 1 1 1 1 0 NB. incorrect
>
> A findinrowsM 'TAAG'
> 0 0 0 1 0 NB. correct
> A findinrowS 'TAAG'
> 0 1 0 1 0 NB. incorrect
>
>
> --
> View this message in context: http://old.nabble.com/Search-for-ordered-
> letters-within-lines-of-matrix-tp32287342s24193p32295181.html
> Sent from the J Programming mailing list archive at Nabble.com.
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm