Problem Description
This program explores the phenomena of "runs" when
flipping a coins. A run is a string of consecutive flips with
identical results. Long runs seem to occur more often than we think
they should.
Background & Techniques
Natalie Angier in her book "The Canon" has a chapter about probabilities
which describes an experiment conducted by a math professor with new
classes. Each student flips a coin 100 times and records the results with
the instructor out of the room. The hook is that half of the class
actually flips a coin, the other half "flips" mentally, i.e. just records
what they imagine the results of the next flip might be. The instructor
returns to the room and sorts the results according to whether they
represent real or imagined tosses.
The trick works because most minds do not appreciate the occurrence of
"runs", sequences of tosses with the same result. Almost every set of 100
tosses will have have one or more sets of 5 or more Heads or Tails in a row.
(The expected number of such strings is slightly more than 3.0.) Very few of
the humanimagined results
will have even one such string. This program verifies the result by
mathematically flipping coins and comparing experimental with expected
results for a range of "same result" string lengths.
Two buttons represent alternative experimental techniques. Button1
simulates the experiment described above, throw 100 coins per trial for the
number of trials specified and record number of runs of length N.
The 2nd button reports runs of length N per 100 trials if only N are thrown
at a time. Until you think about it, it's surprising that the second method
produces results 4 times larger than Method 1. This is because when throwing
N coins per trial and counting runs of length N, the preceding and following
coins do not matter. If we
throw 100 coins looking for runs of length N, the coins preceding and
following a "success" must show the
opposite side. So runs of length 3 Heads require a "run" of length
5 with value THHHT which have a probability of 1/32 compared to 1/8 for runs
of length 3 when only 3 coins are thrown.
Nonprogrammers are welcome to read on, but may
want to skip to the bottom of this page to download
executable version of the program.
Notes for Programmers
Nothing too hard except figuring out why flipping a
coin 100 times and counting runs of length N has only 1/4 the occurrences of
runs of length N compared to N coins thrown 100 times and length N
runs counted. Procedure "Trial" simulates
results if NbrCoins are thrown consecutively and counts the number of
runs for each length from 1 to Runlength. Counts of number of
Heads runs and Tails runs are returned in separate arrays.
To simulate the original experiment, Trial(100,
10, HCount, TCount) is called Nbrtrials times, each call
representing one trial. Nbrtrials is set from the value of the
Radio Group box, Radiogroup1.. The totals from each trial for
all 10 run lengths are totaled in arrays HeadRuns and
TailRuns. These totals, divided bynbrtrial are reported as
observed values.
For the 2nd button, simulating runs of length N
observed when only N coins are flipped in each trial, an outer loop for each
run length 1 through 10 contains an inner loop calling Tria( i, i, HCount,
TCount) Nbrtrials times and summing only Hcount[ i ]
and TCount[ i ] for i= 1 to 10.
Running/Exploring the Program
Suggestions for Further Explorations
?
Original Date: January 13, 2009 
Modified:
February 18, 2016 
