TubeSum ← Transcribe a video

Calculating pi from coin flips (without randomness)

Transcribed Jun 28, 2026 Watch on YouTube ↗
Intermediate 8 min read For: Math enthusiasts, programmers, and anyone curious about probability and pi.
368.3K
Views
16.8K
Likes
1.5K
Comments
50
Dislikes
5.0%
🔥 High Engagement

AI Summary

Eight years ago, the creator flipped a coin 10,000 times to study how often it lands on its edge. Recently, a new mathematical discovery revealed that if you flip a coin until you have more heads than tails, the average ratio of heads to total flips converges to π/4. This video uses that fact to calculate π from the old coin-flipping data, explaining the math behind it and showing the Python code used to process the results.

[1:28]
New math fact: π/4 from coin flips

The video is about a new mathematical fact: if you flip a coin until there are more heads than tails, the average ratio of heads to total flips is π/4.

[0:08]
10,000 coin flips from 8 years ago

The creator flipped a coin 10,000 times eight years ago to study edge landings, and now uses that data to calculate π.

[3:54]
Range of average ratio

The range of possible average ratios is between 0.5 and 1, which narrows π to between 2 and 4.

[8:33]
Catalan numbers count sequences

The number of valid sequences of a given length is given by Catalan numbers.

[13:20]
Connection to arcsin(1)

The series from the coin-flipping process matches the Taylor expansion of arcsin(1), which equals π/2, leading to the average ratio being π/4.

[16:07]
Edge landings: 14 times

The coin landed on its edge 14 times out of 10,000 flips.

[16:43]
Python code for calculation

The Python code processes the data, calculates the average ratio, and multiplies by 4 to get π.

[21:24]
Result: π ≈ 3.2266

The calculated value of π from the data is 3.2266.

Clickbait Check

85% Legit

"The title is accurate: the video does calculate pi from coin flips, and the 'without randomness' refers to using a deterministic series derived from the flips, not random sampling."

Mentioned in this Video

Tutorial Checklist

1 16:47 Open the coin flip data spreadsheet (e.g., using Python's openpyxl library).
2 17:02 Initialize variables: sequence_count = 0, running_ratio_total = 0, flip_count = 0, head_count = 0.
3 17:38 For each flip result: if result is 'H', increment head_count; if result is not 'E', increment flip_count.
4 18:13 Check if the sequence has ended (more heads than tails). If so, calculate ratio = head_count / flip_count, add to running_ratio_total, increment sequence_count, and reset flip_count and head_count to 0.
5 20:35 After processing all flips, calculate average_ratio = running_ratio_total / sequence_count, then pi = average_ratio * 4.
6 20:49 Print the calculated pi value.

Study Flashcards (10)

What is the average ratio of heads to total flips when you flip a coin until there are more heads than tails?

medium Click to reveal answer

π/4

2:04

What sequence of numbers counts the number of valid head/tail sequences of a given length in this coin-flipping problem?

hard Click to reveal answer

Catalan numbers

8:33

What is the value of arcsin(1) in radians?

hard Click to reveal answer

arcsin(1) = π/2

13:20

How many times did the coin land on its edge in the 10,000 flips?

easy Click to reveal answer

14 times

16:07

What value of pi was calculated from the 10,000 coin flips?

medium Click to reveal answer

3.2266

21:24

Who discovered the mathematical fact linking coin flips to π/4?

medium Click to reveal answer

James Propp

14:22

What is the range of possible average ratios of heads to total flips in this coin-flipping game?

medium Click to reveal answer

0.5 to 1

3:54

What is the formula for the nth Catalan number?

hard Click to reveal answer

1/(n+1) * (2n choose n)

11:39

What mathematical structure appears when you draw a tree diagram of the coin-flipping paths?

medium Click to reveal answer

Pascal's triangle

10:19

Why did the calculated pi value (3.2266) differ from the true value (3.14159...)?

medium Click to reveal answer

It converges slowly.

21:28

💡 Key Takeaways

📊

Pi/4 from coin flips

Reveals a surprising connection between a simple coin-flipping game and the constant π.

2:04
💡

Catalan numbers appear

Shows how a well-known combinatorial sequence naturally arises in this probability problem.

8:33
🔧

Arcsin series matches

Demonstrates the key mathematical step linking the coin-flipping series to π via the arcsin function.

13:20
📊

14 edge landings

Provides a concrete data point from the original experiment, showing the rarity of edge landings.

16:07

Calculated pi = 3.2266

Shows the practical outcome of applying the theory to real data, highlighting slow convergence.

21:24

✂️ Creator Tools: Viral Hooks

AI-generated clip ideas for Shorts based on the transcript

Coin Flips Reveal Pi?!

46s

A new math discovery: flipping a coin until heads outnumbers tails gives pi/4, a surprising connection.

▶ Play Clip

Pi Is Between 2 and 4

30s

Using coin flips, we narrow pi to between 2 and 4 – a simple yet surprising fact.

▶ Play Clip

The Coin Flip Tree Secret

46s

Visualizing coin flip sequences with a tree diagram reveals the Catalan numbers.

▶ Play Clip

We Computed Pi from Coin Flips

60s

After 10,000 flips, the calculated pi is 3.2266 – better than expected but still off.

▶ Play Clip

Impossible Coin Edge Trick

52s

A staged collaboration where a coin lands on its edge repeatedly – hilarious and controversial.

▶ Play Clip

[00:08] [music]

[00:08] Eight years ago, a younger version 

[00:13] 10,000 times. If you're wondering 

[00:18] look, we don't welcome those sorts of questions 

[00:23] how often it would land on its edge. And later on, 

[00:31] it landed on its edge if you want to see if you 

[00:35] and I have a ridiculous joke collaboration we 

[00:41] That'll be right at the end of the video. See if 

[00:46] we're going to speed forward 8 years to 

[00:52] That's because of Pi Day. Yes, a few years ago I 

[00:57] was thinking, but I've finally come up with a use 

[01:02] So, hey, happy Pi Day 2026. Although, shouldn't 

[01:07] Spoiler. This is not a video about that. 

[01:13] about flipping Thank you. a coin to see 

[01:28] Yes. Late last year, a new bit of math 

[01:33] keep track of if it's heads or tails, and you 

[01:39] And let's say you do that over and over. And 

[01:43] I stop whenever there are more heads than tails, 

[01:48] where I compare the number of heads to the 

[01:51] more heads than tails, but how many more? And if 

[01:59] turns out, and yes, this is why it's a Pi 

[02:04] It's pi. It's pi on four. If you flip a coin until 

[02:14] on four. So that's what we're going to do. This 

[02:19] coin flips, which has actually come together quite 

[02:24] us calculating pi on the moon. You may have seen 

[02:29] Sadly, like a lot of space missions, it's been 

[02:33] Pi Day hopefully. Previously, previously, 

[02:39] I was going to try and break the record. Turns out 

[02:42] that's also delayed, but will happen. link in the 

[02:47] So, what I'm going to do is basically go back to 

[02:51] but this time instead of doing long tedious 

[02:56] a coin 10,000 times by hand. And from that, we 

[03:05] no one noticed that you get this value of pi on 

[03:12] And so I'm like, well, this is great. Breaking 

[03:16] to explain why you get pi when you flip a coin. 

[03:23] Let's do it. Right. I'm going to use these to 

[03:27] can kind of arrange them across here. 

[03:31] we've got a pretty tight range on what the average 

[03:37] boom, straight out of the gate, you flip a heads. 

[03:42] and it's 100% 100% heads. It's the highest 

[03:48] thousands of flips before eventually we have 

[03:54] it will have just because there's so many just 

[04:02] Because we're calculating pi on four, 

[04:07] to between two and four, which you know, compared 

[04:16] Now, what if we didn't get head straight 

[04:20] Well, now we're going to have to keep going. 

[04:24] three flips. It can't be two because 

[04:30] right? And but now it's 50/50. Has to be more 

[04:37] another heads. So now that's the Whoops. Shortest 

[04:46] And that's a well, I guess that's a a half time a 

[04:52] of happening. And the ratio is two out of three. 

[04:59] The next shortest would be five flips. So 

[05:04] that would have to be tails there. Okay. And then 

[05:12] right? Cuz we need to get it needs to be three 

[05:17] So it would look like that. There it is. Okay. 

[05:22] we flip this heads. And that's the one that 

[05:26] probability of this sequence happening half times 

[05:31] five. We can add that in and the ratio is 3 out of 

[05:38] Yeah, this one works. But so does so is this 

[05:45] That's five long and would end at the same 

[05:51] I'll pick that up later. There's I can replace 

[05:57] for each run of coins, we need the probability, we 

[06:04] are. So we multiply this one by two. Let's have 

[06:12] and we're going to think about what sequences 

[06:16] by end, it means that has to be us flipping a 

[06:21] more heads than tails and we stop. And at no point 

[06:26] otherwise we would have stopped including the very 

[06:30] would have stopped on the heads. The second one 

[06:35] Let's start by the case where we flip three tails 

[06:41] heads come slamming back and they get it right at 

[06:49] which this one means we've got more heads and 

[06:55] this third tails here, that could happen later. 

[07:00] was a tails. That would work nicely. We can move 

[07:05] move it down again. That could be uh heads. That 

[07:12] because if this was heads and that was tails, 

[07:18] at that. Two tails, three heads, we would have 

[07:23] So, now we're up to uh three alto together. Now, 

[07:30] Now, if that's a heads, this one can't 

[07:34] heads than tails. It's got to be tails like 

[07:39] And then these can go either way. This is either 

[07:45] Both of those work. You can't delay it any 

[07:50] pause and go through that yourself, you're very 

[07:55] which I'm pointing down here because I've still 

[07:58] the other night, and I got all these sketches 

[08:04] get in the sequence of heads and tails and tails 

[08:09] and I was right." So, I was able to fill that into 

[08:15] nine. There's 14 ways to do it. I didn't bother 

[08:26] the online encyclopedia of integer sequences and 

[08:33] And I was like, turns out I do. So why the 

[08:40] I then drew a diagram which I'm going to recreate 

[08:45] where I thought, you know what? Let's represent on 

[08:51] down. If you get a heads, you go up. I had to roll 

[08:57] And the goal is to end up above water. Very 

[09:03] and then if your first flip is a heads, you're 

[09:10] you're down here. To clarify, when 

[09:15] once we're one above this blue line. Because 

[09:21] being one above our starting point means we've 

[09:27] expanded the tree diagram because the next 

[09:32] This one would bring you even further below the 

[09:37] heads. And there's only one way that that's 

[09:42] but there are multiple ways. If you go up here 

[09:51] then if you count that, you're like, "Oh, actually 

[09:53] way down and all the way back and out or down, up, 

[09:59] this diagram of all the ways you can flip 

[10:06] up and all the times that you break the 

[10:11] count the number of paths. Ah, you know what this 

[10:19] it's Pascal's freaking triangle. If you'd like 

[10:23] Catalan numbers, my friend Sophie Mlan already 

[10:28] highly recommend you check that out. And it works 

[10:33] counting the number of ways you can get to any 

[10:37] to normally cross over in the middle. Ah, it's 

[10:43] But for our purposes, we're just going to 

[10:46] the number of possible head or tail sequences. 

[10:52] So we can take our table from before and put it 

[10:58] n equals 0. The zeroth Catalan number which is 

[11:05] And the formula in general is going 

[11:12] multiplied by the nth Catalan number multiplied 

[11:21] the table. But now you put in whatever value of 

[11:26] we want to sum these from n equals z up infinitely 

[11:35] I wrote down here last night. You can see there 

[11:39] and over here next to it, I've written the formula 

[11:46] by 2 n choose n. And you can put that in terms 

[11:53] And now we have one big chunky equation that 

[12:01] all the way up. We just got to work out how we 

[12:09] kind of substitution or a way to rearrange 

[12:17] It's arc sign. It's the inverse 

[12:23] as a series. Look at that. Isn't that amazing? I 

[12:29] everything from first principles. It'll be a very 

[12:34] boring video. So at some point you've just got to 

[12:40] series expansion of aride. If you want to look 

[12:45] binomials and once again Pascal's triangle. Lovely 

[12:52] I'm saying is doesn't that look similar? In fact, 

[12:59] one. Just put that in. Why not? And that means the 

[13:05] looks pretty much exactly like what we had before. 

[13:14] whatever the average ratio of heads to tails is 

[13:20] sign of one? The inverse sign of one. What value 

[13:27] It's pi on 2. So pi on 2 equals twice the average. 

[13:35] angry. I mean, here's the thing. We're not 

[13:42] dogs come over to see why I'm getting emotional. 

[13:48] different length sequences of flips and adding 

[13:52] we'd anticipate and we're not surprised that you 

[13:58] classic pi. But I expect them to be separate 

[14:06] for pi happens to match a series for flipping a 

[14:16] Thank goodness I got my therapy dog right here. 

[14:22] was discovered last year by a mathematician I know 

[14:27] blog post for this pi day going through all the 

[14:32] You can check it out if you want to go through 

[14:37] if you're into that kind of thing. But 

[14:42] like a such a good fact. I need to do a thing 

[14:46] over and over and over again and calculate pi by 

[14:52] turns out it's already been done by my longtime 

[14:59] was flipping a coin 10,000 times. I've had this 

[15:06] thick a three-sided coin would have to be, which 

[15:13] tails, or edge. And I've talked about this 

[15:18] but I found the current state-of-the-art. 

[15:23] single paper. In fact, to this day, if you go to 

[15:28] the one citation for landing on edge is the 

[15:35] edge from 1993. So, I thought I would recreate 

[15:44] in an attempt to investigate that. 

[15:48] the data. I did recreate their experiment by 

[15:54] off a horizontal surface a thousand times. Then, 

[16:01] if you want to have a look at the data. You can 

[16:07] landed on its edge 14 times. Now this whole 

[16:13] a whole section in my book humble pie. But the 

[16:20] until now. Until I wanted to calculate pi. 

[16:26] link to this below if you want to check it out 

[16:29] every single coin. Wow, that was a late night. 

[16:35] every single landing one. And that's just my kind 

[16:43] we need to analyze this, which means we got 

[16:47] fun to write the code. So, all I'm doing here is 

[16:55] I've I've I've set up the name of the file and 

[17:02] we've been through and that starts with 

[17:06] useful names. That's also zero. And then for each 

[17:14] and how many flips? What are 

[17:20] Let's ignore them. [laughter] Let's say they 

[17:26] got to be heads or tails. Lowerase H or T. So what 

[17:38] then we increment head count. So that goes up by 

[17:55] that's our total number of flips. Okay. So, all 

[18:00] heads, we add to the running head count. If it's 

[18:06] flips count. Great. Now, we got to check if we've 

[18:13] we want to work out the ratio of heads to tails in 

[18:19] uh headcount divided by flip count. I could 

[18:25] I like to split things out because it makes my 

[18:29] I'm going to take running ratio total add on 

[18:35] So, uh what do we call our sequence count? Count 

[18:42] me. So, we add one onto that. Now, we want to 

[18:48] flip count and head count now get set back to 

[18:55] I can't increment flip result. That's 

[18:59] Okay, that fixed. I kind of want to check it's 

[19:07] it first without calculating the result. That's 

[19:14] and then down here we'll print what we think 

[19:21] It'll do that for all 10,000 flips. make sure it 

[19:26] You never know with code. It's like if you just 

[19:32] make sure everything's working properly. It's 

[19:37] Ah. Oh, there it is. It ran. Oh, these 

[19:42] So, that was a super long run. Look at it. And 

[19:48] Next one was a heads. So, it was one heads was 

[19:57] 10 11 flips of which one two three four five six. 

[20:09] tipped it over to six and five. It stopped and 

[20:17] I'm going to undo that one. Now once 

[20:27] Should we do it all at once? Should we just print 

[20:35] pi val equals running ratio total divided by count 

[20:44] divided by how many there are. That gives us 

[20:49] And then we print pi val. So this is it folks. 

[21:00] We're going to zoom. Let's get right in. I know 

[21:04] Ready? Okay. Here we can't see producer Nicole is 

[21:13] person Alex is over there wildly indifferent. 

[21:24] That's better than I was braced for 

[21:35] For everyone who keeps a running record of 

[21:42] That's good stuff. Obviously, while I was 

[21:47] did some ridiculous bits to camera and then I 

[21:51] in a fake collaboration where a coin 

[21:57] on its edge. In a previous video, I said there 

[22:02] of it landing on its edge. And even though you 

[22:07] misconception that that can happen when it's 

[22:13] it lands on a physical surface. It will 

[22:18] that's impossible, you need some very nice 

[22:23] and some things you might not know. The first 

[22:29] take a close look at what happens. If you watch 

[22:41] Okay. Okay. All right. Okay. About about the 

[22:47] No, you didn't. No. Seriously. Seriously. I 

[22:51] I landed on its edge. Is we pro? We No, I know. I 

[22:56] it happened. Do it again. There's no Look, 

[23:07] See? No. Yes. Wait. No. Yeah. I don't 

[23:12] happen. I know. I know. But I did 

[23:17] Okay. You're kind of the worst 

[23:23] I've got some terrible news about our collab. 

[23:32] See you later.

[23:38] Yes, Steve Mold and Tom Scott did stand around 

[23:45] coin to land on an edge. Absolute legends. Sorry 

[23:51] here we are. And now back to Modern Matt for the 

[23:59] 2026 literally 26 in the digits of pi. So write 

[24:08] Ah, fantastic. Now, some updates for the people 

[24:14] we will do pi by hand again. We've done some 

[24:20] of research. We got a whole team on it. It's going 

[24:25] long. I'm going to need so many volunteers that 

[24:31] haven't really got a plan for that. We're trying 

[24:36] a success on the first launch, the leftover 

[24:41] which means we can probably do it at the scale 

[24:47] 12 [music] months warning if you want to come 

[24:52] Link in the description for the sign up form. 

[24:56] more than a year in advance when we're going to 

[25:01] Moonpie, the update is out. That's a lot of fun. 

[25:08] will launch um at some point this year. Um we'll 

[25:15] thanks for watching the videos. Oh my goodness. 

[25:19] And I couldn't have done it without Passmat. 

[25:25] for all things Catalan numbers. Jim Prop for 

[25:31] uh I'll link his blog post. You should check that 

[25:36] for waiting for a ridiculous amount of time for 

[25:43] That's a pretty accurate representation of what 

[25:49] it. Thanks. Thanks for supporting the videos. 

[25:54] I feel like Pi Day is like uh end of one year. 

[25:59] years. I run on pi years. So, that was the end of 

[26:07] go uh into the next one. And so, um that's it. So, 

[26:22] Oh, no. [laughter] Oh. Oh, that's so unfair.

⚡ Saved you time reading this? Transcribe any YouTube video for free — no signup needed.