Heads & Tails

Jim Hurley jhurley at infostations.com
Sat Dec 10 08:01:31 EST 2005


>
>Message: 7
>Date: Fri, 9 Dec 2005 13:58:46 -0700
>From: Mark Greenberg <markgreenberg at cox.net>
>Subject: Re: Heads & Tails
>To: use-revolution at lists.runrev.com
>Message-ID: <0AFB8EEF-AA0C-4672-B295-358DBA22F585 at cox.net>
>Content-Type: text/plain;	charset=US-ASCII;	delsp=yes; 
>	format=flowed
>
>	Yes, but the original post (quite a while ago) was looking for a way 
>to determine how many times h occurred in singles, doubles, triples, 
>etc.  Your script counts how many heads and tails there are total.
>	There were some non-RegEx solutions offered, but they were long.  
>RegEx shortens the length of the solution quite a bit.  I can't 
>determine whether the RegEx solution is faster because I am using an 
>older version of Rev which has slower RegEx.
>
>		Mark

Mark,

Sorry. Should  have realize there  was more to it that.

And there is another way to skin that cat: separate the sting of h's 
and t's into words and do a word count using an array.

on mouseUP
   put field 1 into tText
   put char 1 of tText into tLastChar
  --Separate the string of h's and t's into words
   repeat for each char c in tText
     if c = tLastChar then
       put c after results
     else put  space & c after results
       put c into tLastChar
   end repeat

   --Do a word count
   repeat for each word tWord in results
     add 1 to tWordCount[tWord]
   end repeat

   --Display
   combine tWordCount with return and comma
   put tWordCount into field 2
end mouseUP

Jim



More information about the use-livecode mailing list