Trying to code the fastest algorithm...

Brian Yennie briany at qldlearning.com
Sun Jun 5 19:15:31 EDT 2005


Here's one off-the-cuff idea, dunno how it will stack up.

## create an array that looks like
## array['word1'] => 1, array['word2'] => 2, etc
repeat for each item W in wordList
    put wordNum into wordArray[W]
end repeat

## loop through sentences
repeat for each line l in tSentences
    put 1 into tOffset

    ## check each word
    repeat for each word tWord in l

       ## quick array check to see if we want this word
       ## note: "it" now contains the number of the word we found
       get wordArray[tWord]
       if (it is not empty) then put tOffset&comma after tResultLine

       add 1 to tOffset
    end repeat
    if (tResultLine is not empty) then put (char 1 to -2 of 
tResultLine)&cr after tResults
end repeat
delete last char of tResults

Hope it helps- no time to test out, but the idea is hopefully clear.




More information about the use-livecode mailing list