Well, a bit of perseverance put me over the top. My
only misgiving about the solution I'm posting here is
the conditional aspect of cullOne.

This algorithm differs, modestly, from what Ewart Shaw
used (which is also the one described on Wikipedia). 
The difference is that the length of the solution is
not determined prior to backtracking.

NB. Longest Common Subsequence

lcsTH=: dyad define
 |.x{~ 0{"1 cullOne^:_ (\:~~ +/@|:) 4$.$. x =/ y
)

cullOne=: verb define
 if. (#y) = First0=.0(= i. 1:) 1,*./|: 2 >/\ y 
 do. y  else. y #~ 0 First0}(#y)#1  end.
)

--
Tracy B. Harms
 
     A good programming language is a conceptual universe
     for thinking about programming.
                                        Alan Perlis


      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to