Heads & Tails
Mark Greenberg
markgreenberg at cox.net
Fri Dec 9 06:35:10 EST 2005
Here's another solution for the problem of finding the runs of heads
in a series of coin flips:
Function TheRuns Data --in the form of tththhhhtthhth...
Local P1, P2=1
Repeat with i = 1 to 12
Put True into M;Put Data into D;Put 0 into Ct
Repeat until M is False
Put MatchChunk (D,"(?:^|t)(h{" & i & "})(?:t|$)",P1,P2) into M
If M then Add 1 to Ct
Delete Char 1 to P2 of D
end Repeat
Put Ct & " runs of " & i & Return after Report
end Repeat
Return Report
end TheRuns
I don't post often, so I'll wish you all a happy holiday season now.
Enjoy!
Mark Greenberg
More information about the use-livecode
mailing list