[quick post publication note – one of my former students thought that I was a little too loose with my language with the kids in this project. He thought, quite fairly, that I needed to be clearer about the fact that it wasn’t just one trial that we were looking at, but rather looking at many rounds and the expected number of flips for HTT to appear the first time and the expected number of flips for HTH to appear the first time.

Sorry for not being clearer about that point in this post, but I’m glad to have people pointing out ways to make these posts better.]

Saw this incredibly interesting probability problem on Twitter yesterday:

If you click through to the Peter Donnelly Ted Talk video, you’ll see a discussion of the problem starting around 4:00.

I had a hard time getting my arms around Donnelly’s explanation of the answer to the problem, and ended up spending a couple of hours last night thinking of how to explain this problem to the boys. Eventually I decided a computer-based approach might be the most enlightening way since that would allow us to talk informally about the math and then see the results relatively quickly. It ended up being one of the more interesting projects that we’ve done in a while.

We started with a quick explanation of the problem followed by some neat discussion from the kids. It was really interesting to me to hear their thoughts about probability.

Next up we tried a little “coin flipping.” Except that we did some dice rolling because it is hard to see coin flips on camera. Even numbers were “heads” and odd numbers were “tails.” It took 5 rolls to get a HTH sequence and it took only 3 rolls to get HTT. The boys understood that one time looking for each sequence wasn’t enough to tell us what the expected value was, and suggested instead that we’d need an infinite number of trials – ha ha.

Because of the random luck of getting HTT in 3 rolls, I decided to take a little diversion to talk about the probability of that happening. Although this diversion made the project a little longer, I’m glad that we took a closer look at this situation since computing the probability of getting HTT in 3 rolls was a little bit confusion to the boys. The mathematical idea we are talking about here is independent events.

Next we switched over to a little computer program I wrote last night. I know that some people have strong feelings about Khan Academy, but their computer program interface makes it easy to share programs like this one – feel free to play around with it:

A simple little program for HTH and HTT

The first part of the video below is just me explaining the computer program. After a couple of minutes we begin using the program to analyze the coin flipping game. We start by looking at how often we get a match in round 3. From the calculations we did in the previous video we expect to find a match 12.5% of the time. That’s about what we find. We also find that we get a match on round 4 about 1/8th of the time.

Now we took a second diversion to take a closer look at getting a match on round 4. Again this exercise proved to be slightly confusing at fist, but the boys seemed to catch on fairly quickly. Their understanding led to a great discussion of what could happen on round 5. The reason round 5 is important is that’s the first time you see a difference between the two sequences:

Finally we returned to our computer program to look at what happens in round 5. We found that both sequences behaved more or less how our conversation from the prior video predicted (despite my incorrect calculation of 75% of 12.5 . . . sheesh).

After that we looked at how many flips we expect to have to do to find a match to each of our sequences. Unfortunately and super unluckily our camera ran out of storage in the middle of this discussion, so I had to break this discussion into two videos. Sorry about that 😦

So, a super fun project and a super interesting math problem. Thanks to Bob Lochel and Math Curmudgeon for sharing it!

Thanks for this interesting post! While reading along (and not having seen your program yet), I quickly hacked my own little program for this experiment, and obviously I interpretated the original question a bit differently: In my version, the program checks in each trial for both HTT and HTH, keeping track which one appears first (and after how many flips).

Turns out that the events “HTT appears first” and “HTH appears first” both seem to happen the same number of times, with each trial lasting 5 flips on average.

Here’s a spin-off of your original program: https://www.khanacademy.org/computer-programming/spin-off-of-htt-and-hth/4905745359044608 (I tried to keep the changes to a minimum, see https://gist.github.com/noniq/13e5587f8f45bb49f677/revisions for a diff).

So even though if looking for a specific sequence only HTH appears later than HTT (10 flips vs. 8 flips), I think one could argue that the answer to “which sequence is more likely to appear first: HTT or HTH” is: “neither; both have a 50% probability of appearing first in a given sequence of flips”.

I agree. I think the title of the post implies the question Stefan asked, to which the answer is neither. The question actually being answered in the post (and the TED talk) is “what is the average number of flips needed to achieve HTH and what is the average number of flips needed to achieve HTT?” This is a different question, and thus, a different answer. Still an interesting problem, just think the title is a bit misleading.