All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Coin tossing (Posted on 2004-06-11)
I threw a coin n times, and never got three tails in a row. I calculated the odds of this event, and found out they were just about even; 50%-50%. How many times did I throw the coin?

A second question: what were the chances of having not gotten three heads in a row either?

 See The Solution Submitted by Federico Kereki Rating: 3.6667 (6 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 simulations Comment 25 of 25 |

The following program simulates 100,000 trials each at n = 3 through 12, and reports the results when, as in the stated condition, the tossing has continued until that many tosses have been made, under the assumption that as soon as three heads or three tails in a row has been reached, tossing ends.

DEFDBL A-Z
OPEN "ctsim1.txt" FOR OUTPUT AS #2
RANDOMIZE TIMER
FOR n = 3 TO 12
PRINT #2, n
bothCt = 0: neitherCt = 0: only3TCt = 0: only3HCt = 0
FOR trial = 1 TO 100000
headCt = 0: tailCt = 0
FOR toss = 1 TO n
heads = INT(2 * RND(1))
tailCt = 0
ELSE
tailCt = tailCt + 1
END IF
t = toss ' hold for later, as NEXT leaves incremented by 1
IF tailCt = 3 THEN had3T = 1: EXIT FOR
IF headCt = 3 THEN had3H = 1: EXIT FOR
NEXT
IF t = n THEN
bothCt = bothCt + 1
ELSE
only3TCt = only3TCt + 1
END IF
ELSE
only3HCt = only3HCt + 1
ELSE
neitherCt = neitherCt + 1
END IF
END IF
END IF
NEXT trial
PRINT #2, "        hadTTT   noTTT"
PRINT #2, "hadHHH"; : PRINT #2, USING " ####### #######"; bothCt; only3HCt
PRINT #2, " noHHH"; : PRINT #2, USING " ####### #######"; only3TCt; neitherCt
PRINT #2, "      "; : PRINT #2, USING " ####### #######"; only3TCt + bothCt; neitherCt + only3HCt
PRINT #2,
NEXT n
CLOSE

The results are

` 3         hadTTT   noTTThadHHH       0   12519 noHHH   12487   74994         12487   87513`
` 4         hadTTT   noTTThadHHH       0    6256 noHHH    6264   62246          6264   68502`
` 5         hadTTT   noTTThadHHH       0    6174 noHHH    6277   50138          6277   56312`
` 6         hadTTT   noTTThadHHH       0    4635 noHHH    4707   40765          4707   45400`
` 7         hadTTT   noTTThadHHH       0    3909 noHHH    4021   32619          4021   36528`
` 8         hadTTT   noTTThadHHH       0    3203 noHHH    3137   26671          3137   29874`
` 9         hadTTT   noTTThadHHH       0    2465 noHHH    2609   21382          2609   23847`
` 10         hadTTT   noTTThadHHH       0    2003 noHHH    2048   17395          2048   19398`
` 11         hadTTT   noTTThadHHH       0    1670 noHHH    1665   13945          1665   15615`
` 12         hadTTT   noTTThadHHH       0    1347 noHHH    1405   11445          1405   12792`

As expected, when n=3, all trials proceeded to completion of the three tosses, and in 1/8 of the cases TTT was achieved and in another 1/8 of the cases HHH was achieved.

With 100,000 trials, a 50-50 probability of getting the observed results (going all the way to n tosses, and getting no TTT's) would give 50,000 such results. That is most closely matched when t=5, with 56,312 of that set of events happening and when t=6, with 45,400 of the trials reaching 6 tosses with no TTT. In the latter case, of the 45,400 reaching 6 tosses with no TTT, 40,765 also had no HHH, for a conditional prob of 89.79%.

If on the other hand we always allow the tossing to continue until n tosses have been reached, this opens the possibility that you will get both TTT and HHH.  The simulation program is the same as the above but without the EXIT FOR's.  The results are:

` 3         hadTTT   noTTThadHHH       0   12263 noHHH   12437   75300         12437   87563`
` 4         hadTTT   noTTThadHHH       0   18811 noHHH   18721   62468         18721   81279`
` 5         hadTTT   noTTThadHHH       0   24835 noHHH   25148   50017         25148   74852`
` 6         hadTTT   noTTThadHHH    3104   28210 noHHH   27900   40786         31004   68996`
` 7         hadTTT   noTTThadHHH    6272   30440 noHHH   30680   32608         36952   63048`
` 8         hadTTT   noTTThadHHH   10163   31680 noHHH   31602   26555         41765   58235`
` 9         hadTTT   noTTThadHHH   14363   31988 noHHH   32151   21498         46514   53486`
` 10         hadTTT   noTTThadHHH   18763   31808 noHHH   32097   17332         50860   49140`
` 11         hadTTT   noTTThadHHH   23481   31569 noHHH   30996   13954         54477   45523`
` 12         hadTTT   noTTThadHHH   28055   30167 noHHH   30451   11327         58506   41494`

In this case, it is n=10 that has the closest to a 50-50 split between hadTTT and noTTT.  Since it always goes to completion of the n tosses, all 100,000 are shown.  Of the 49,140 that had no TTT in 10 tosses, 17,332 also had no HHH, for a conditional prob. of 35.37%.

 Posted by Charlie on 2004-06-17 11:12:25

 Search: Search body:
Forums (0)