AW: counting runs

Thomas Fischer fischer at mail.sub.uni-goettingen.de
Mon Oct 31 22:28:50 CST 2005


Hi Jason,

if you just want to count the occurrences of H and T in strings like
> T,T,H,T,T,H,H,H,T,T,H,T,H,H,H,T,H,T,H,T
the easiest (and most likely fastest, unchecked though) way might be to do something like

  put  "T,T,H,T,T,H,H,H,T,T,H,T,H,H,H,T,H,T,H,T" & comma into myString
  put the number of items in myString into totalCount
  replace "T," with "" in myString
  put the number of items in myString into headCount
  put totalCount - headCount into tailCount
  answer "total: " & totalCount & return & \
      "Heads: " & headCount & return &  \
      "Tails: " & tailCount
 
All the best
Thomas


--
Thomas Fischer
Salzburg 

> -----Ursprungliche Nachricht-----
> Von: use-revolution-bounces at lists.runrev.com
> [mailto:use-revolution-bounces at lists.runrev.com]Im Auftrag von Jason
> Tangen
> Gesendet: Dienstag, 1. November 2005 01:22
> An: use-revolution at lists.runrev.com
> Betreff: counting runs
> 
> 
> 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