Trying to code the fastest algorithm...
jbv
jbv.silences at Club-Internet.fr
Sun Jun 5 05:14:43 EDT 2005
Hi list,
I'm trying to build the fastest possible algorithm for the
following task :
I have a variable containing reference words; each "word"
in this variable is considered as an item.
I also have a list of "sentences" (each sentence being a
list of "words" separated by spaces), 1 per line. Each
sentence can contain 1 or more words from the reference,
as well as other words.
I need to determine for each sentence, which words from
the reference are included in it, in which order, and output
a list of offsets.
For example :
reference variable : W1,W2,W3,W4
sentence 1 : Wx W2 Wy Wz W3
output : 2,3
And last but not least, I need to keep only sentences that
contain more than 1 word from the reference.
Here's the fastest script I managed to code :
put "" into newList
repeat for each line j in mySentences
put j into a
replace " " with itemdelimiter in a
put "" into b
repeat for each item i in it
get itemoffset(i,myReference)
if it>0 then
put it & itemdelimiter after b
end if
end repeat
if b contains itemdelimiter then
delete last char of b
put b & cr after newList
end if
end repeat
But I was wondering if there was any faster approach...
Thanks,
JB
More information about the use-livecode
mailing list