An interesting programming challenge

Geoff Canyon gcanyon at gmail.com
Fri Apr 10 00:35:47 EDT 2015


On Thu, Apr 9, 2015 at 8:36 PM, Jerry Jensen <jhj at jhj.com> wrote:

> Here’s my script that gave the right answer the first time too. It runs in
> about 100 msec on a MacBookPro 2.6GHz i7 with Yosemite 10.10.3 and LC 6.7.4
> .
> Its in the button script of the GO button.
>

Really nice! Here's mine, which runs about six times slower if it's just
counting, or about 25x slower as it is -- I wrote it to record all the
lists it finds, which slows it down obviously, but the use of arrays was a
poor choice. Anti-spoiler returns:
















on mouseUp
   put 0 into P
   repeat for each item N in fld "input"
      add 1 to P
      repeat with i = 1 to P
         put N,"" after S[i]["slice"]
         add N to S[i]["sum"]
         if S[i]["sum"] >= 32 then put S[i]["sum"] & tab & (char 1 to -2 of
S[i]["slice"]) & cr after R
      end repeat
   end repeat
   put R into fld "result"
   put the number of lines of fld "result" into fld "count"
end mouseUp



More information about the use-livecode mailing list