NPR puzzle
Jim Hurley
jhurley at infostations.com
Fri Jul 22 13:31:10 EDT 2005
>
>Message: 12
>Date: Fri, 22 Jul 2005 08:04:53 -0700
>From: Geoff Canyon <gcanyon at inspiredlogic.com>
>Subject: Re: NPR puzzle
>To: How to use Revolution <use-revolution at lists.runrev.com>
>Message-ID: <CE0BDA59-691C-4540-B44B-D25AC8286C73 at inspiredlogic.com>
>Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
>
>The engine optimizes the tests in conditionals. So in this statement:
>
>if a=3 and b=2 then...
>
>b never gets evaluated if a is not 3. I rewrote Dick's very nice code
>using this principle, to get rid of the nested if statements.
>Interestingly, my code slowed down a couple milliseconds. Just from
>13 to 15, but I wonder why that might be. Maybe the engine goes to
>the trouble of getting the substrings before doing the tests.
>
>Here's the code:
>
> put the milliseconds into tMilliseconds
> repeat for each line tSymbol in field 2
> put "true" into S[tSymbol]
> end repeat
> repeat for each word W in field 1
> if S[char 1 to 2 of W] and \
> S[char 3 to 4 of W] and \
> S[char 5 to 6 of W] and \
> S[char 7 to 8 of W] and \
> S[char 9 to 10 of W] then \
> put W & return after tHits
> end repeat
> put the milliseconds - tMilliseconds into tElapsedMilliseconds
> put number of lines in tHits && "hits in" \
> && tElapsedMilliseconds && "milliseconds" \
> & return & return & tHits
Geoff,
It appears that RR also does not continue with the nested ifs after
it gets a false. I put a "beep" after the next to last if in Dick's
handler and the handler only beeped once.
Jim
More information about the use-livecode
mailing list