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.@(=/~)
>
> On Fri, Aug 19, 2011 at 7:40 AM, R.E. Boss <[email protected]> wrote:
>> This has the gist of Millers solution.
>>
>>
>> R.E. Boss
>>
>>
>>> -----Oorspronkelijk bericht-----
>>> Van: [email protected] [mailto:programming-
>>> [email protected]] Namens Marshall Lochbaum
>>> Verzonden: donderdag 18 augustus 2011 19:19
>>> Aan: Programming forum
>>> Onderwerp: Re: [Jprogramming] Search for ordered letters within lines of
>>> matrix
>>>
>>> Also, this is a nice version based on your original strategy.
>>>
>>>    findinrows =. [: *@#@> [: ([#~(<{:))&.>/ [: <@I. =/~
>>>    A findinrows 'TAG'
>>> 0 1 0 1 0
>>>
>>> Marshall
>>>
>>> On Thu, Aug 18, 2011 at 1:05 PM, Marshall Lochbaum
>>> <[email protected]>wrote:
>>>
>>> > Here is a version that's morally equivalent to R.E. Boss's, but a bit
>>> > cleaner and more efficient. Note that it only works if the string you
>>> > are finding has all unique characters.
>>> >
>>> >    findinrows =. 0 = (,{~1~:-~)/@(#@[,~i.)"1
>>> >    'TAG' findinrows A
>>> > 0 1 0 1 0
>>> >
>>> > Marshall
>>> >
>>> > On Thu, Aug 18, 2011 at 10:51 AM, R.E. Boss <[email protected]> wrote:
>>> >
>>> >>
>>> >>   'TAG' (i.@>:@#@[ (-:~.)"1 [:(]`[@.(1=-~))/\."(1) #@[ ,.~ i."1) A
>>> >> 0 1 0 1 0
>>> >>
>>> >>
>>> >> R.E. Boss
>>> >>
>>> >>
>>> >> > -----Oorspronkelijk bericht-----
>>> >> > Van: [email protected] [mailto:programming-
>>> >> > [email protected]] Namens Ric Sherlock
>>> >> > Verzonden: donderdag 18 augustus 2011 15:25
>>> >> > Aan: Programming forum
>>> >> > Onderwerp: [Jprogramming] Search for ordered letters within lines
>>> >> > of
>>> >> matrix
>>> >> >
>>> >> > I saw the following thread on comp.lang.apl
>>> >> >
>>> http://groups.google.com/group/comp.lang.apl/browse_thread/thread/8
>>> >> > 9c
>>> >> > 585c9d1a7bd3a#
>>> >> > and was trying to put together a (non-regex) J solution.
>>> >> >
>>> >> > Given the matrix:
>>> >> >    ]A=:
>>> >> > 'CTGGTTGAT','GTAGTCATA','CATGTCTAA','TCGAAAGTT',:'CCGGAGAAG'
>>> >> > CTGGTTGAT
>>> >> > GTAGTCATA
>>> >> > CATGTCTAA
>>> >> > TCGAAAGTT
>>> >> > CCGGAGAAG
>>> >> >
>>> >> > and the list 'TAG'
>>> >> >
>>> >> > Identify the rows of the matrix where the letters in the list occur
>>> >> > in
>>> >> the
>>> >> order
>>> >> > they appear in the list, but not necessarily adjacent to each other.
>>> >> > So the result of a verb findinRows would be:
>>> >> >    A findinRows 'TAG'
>>> >> > 0 1 0 1 0
>>> >> >
>>> >> > I have an answer below but am thinking there may be other
>>> >> > approaches I'm missing
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> > Spoiler alert!!
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> > findinRows=: [: (1 e. ,@:(</))&>/ 2 (([: ($ #. ]) 4 $. [: $.
>>> >> > </)&.>)/\
>>> >> >  [: <@I."1 ="_ 0
>>> >> > -------------------------------------------------------------------
>>> >> > --- For information about J forums see
>>> >> > http://www.jsoftware.com/forums.htm
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> - For information about J forums see
>>> >> http://www.jsoftware.com/forums.htm
>>> >>
>>> >
>>> >
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> ----------------------------------------------------------------------
>> 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