counting runs

Mark Smith mark at maseurope.net
Mon Oct 31 20:29:56 EST 2005


This should also work:



on mouseUp
   repeat 10000
     put  any item of "H,T" after flipList -- just to generate a  
sample list
   end repeat

   put flipList into headsList -- make a copy to work on
   replace "T" with cr in headsList -- split runs of heads into lines
   filter headsList without empty -- get rid of empty lines
   repeat for each line L in headsList
     add 1 to resArray["Heads",length(L)]
   end repeat


   --do same for tails
   put flipList into tailsList -- make a copy to work on
   replace "H" with cr in tailsList
   filter tailsList without empty
   repeat for each line L in tailsList
     add 1 to resArray["Tails",length(L)]
   end repeat


   put the keys of resArray into kList
   sort lines of kList numeric by item 2 of each
   repeat for each line L in kList
     put L into desc
     replace comma with "x" in desc
     put desc && resArray[L] & cr after rList
   end repeat
   put rList
end mouseUp

if the Hs & Ts are separated by commas to start with, just 'replace  
comma with empty in flipList'.



Mark

On 1 Nov 2005, at 00:22, Jason Tangen wrote:

> Hello,
>
> I'm trying to solve a seemingly simple problem and I could use some  
> help. A coin flip will come out "Heads" or "Tails" and will  
> produce, for example, the following series for 20 flips:
>
> T,T,H,T,T,H,H,H,T,T,H,T,H,H,H,T,H,T,H,T
>
> I need to count up the number events for a particular run.  For  
> example,
>
> Heads x 3 = 2
> Heads x 2 = 0
> Heads x 1 = 4
> Tails x 1 = 4
> Tails x 2 = 3
> Tails x 3 = 0
>
> I need to account for runs up to 60 (rather than 3 above) for  
> hundreds of flips (rather than 20 above).
>
> I've been using a very clumsy multiple if-then solution to date,  
> but this quickly becomes difficult with many runs.
>
> Can someone point me in the right direction?
>
> Cheers,
> Jason
> _______________________________________________
> 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