NPR puzzle

Lynch, Jonathan bnz2 at cdc.gov
Thu Jul 21 17:22:36 EDT 2005


I humbly bow before thee...

-----Original Message-----
From: use-revolution-bounces at lists.runrev.com
[mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of Dick
Kriesel
Sent: Thursday, July 21, 2005 5:20 PM
To: How to use Revolution
Subject: Re: NPR puzzle

Here's a solution that takes 10 milliseconds on a 1GHz PowerBook G4.

The main reason for the speed improvement over previous solutions is
that
array look-ups are typically faster than string searches.

  put the milliseconds into tMilliseconds
  repeat for each line tSymbol in field 2
    put "true" into tSymbolArray[tSymbol]
  end repeat
  repeat for each word tWord in field 1
    if tSymbolArray[char 1 to 2 of tWord] then
      if tSymbolArray[char 3 to 4 of tWord] then
        if tSymbolArray[char 5 to 6 of tWord] then
          if tSymbolArray[char 7 to 8 of tWord] then
            if tSymbolArray[char 9 to 10 of tWord] then
              put tWord & return after tHits
            end if
          end if
        end if
      end if
    end if
  end repeat
  put the milliseconds - tMilliseconds \
      into tElapsedMilliseconds
  put number of lines in tHits && "hits in" \
      && tElapsedMilliseconds && "milliseconds" \
      & return & return & tHits

-- Dick


_______________________________________________
use-revolution mailing list
use-revolution at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list