[0:08] [music] [0:08] Eight years ago, a younger version  of me sat down and flipped a coin   [0:13] 10,000 times. If you're wondering  why would anyone do that,   [0:18] look, we don't welcome those sorts of questions  around here. But more to the point, I want to see   [0:23] how often it would land on its edge. And later on,  I'll explain why I was doing that, how many times   [0:31] it landed on its edge if you want to see if you  can have a guess. 10,000 flips, how many edges,   [0:35] and I have a ridiculous joke collaboration we  shot, which has never seen the light of day.   [0:41] That'll be right at the end of the video. See if  you can guess who else is involved. But for now,   [0:46] we're going to speed forward 8 years to  when these flips finally became useful.   [0:52] That's because of Pi Day. Yes, a few years ago I  flipped a coin 10,000 times. I don't know what I   [0:57] was thinking, but I've finally come up with a use  for that footage. I'm going to use it this Pi Day.   [1:02] So, hey, happy Pi Day 2026. Although, shouldn't  have said that. Forget [music] it's Pi Day.   [1:07] Spoiler. This is not a video about that.  This is a video about flipping a coin to   [1:13] about flipping Thank you. a coin to see  what the ratio between heads and tails is. [1:28] Yes. Late last year, a new bit of math  dropped relating to if you flip a coin,   [1:33] keep track of if it's heads or tails, and you  stop when there are more heads than tails.   [1:39] And let's say you do that over and over. And  then you ask the question, hang on a second. If   [1:43] I stop whenever there are more heads than tails,  what's the average ratio of all those sequences   [1:48] where I compare the number of heads to the  number of tails? And there's going to be   [1:51] more heads than tails, but how many more? And if  you calculate that and work it out in general,   [1:59] turns out, and yes, this is why it's a Pi  Day video. And look, I'm as angry as you are.   [2:04] It's pi. It's pi on four. If you flip a coin until  there are more heads than tails, the ratio is pi   [2:14] on four. So that's what we're going to do. This  Pi Day, I'm going to calculate pi from my 10,000   [2:19] coin flips, which has actually come together quite  well. Previously, this Pi Day was going to be   [2:24] us calculating pi on the moon. You may have seen  the update about that that went out recently.   [2:29] Sadly, like a lot of space missions, it's been  delayed. So, we can't do that. That would be next   [2:33] Pi Day hopefully. Previously, previously,  there should have been a Pi by hand year.   [2:39] I was going to try and break the record. Turns out  that's going to take longer than I expected. So,   [2:42] that's also delayed, but will happen. link in the  description if you want to sign up for updates.   [2:47] So, what I'm going to do is basically go back to  normal. I'm going to do a standard pi by hand,   [2:51] but this time instead of doing long tedious  working out by hand, I've previously flipped   [2:56] a coin 10,000 times by hand. And from that, we  can extract a value of pi. And unbelievably,   [3:05] no one noticed that you get this value of pi on  four from multiple coin flips until last year.   [3:12] And so I'm like, well, this is great. Breaking  news. So here's what we're going to do. I'm going   [3:16] to explain why you get pi when you flip a coin.  Then we're going to get pi from flipping a coin.   [3:23] Let's do it. Right. I'm going to use these to  represent a sequence of heads and tails. We   [3:27] can kind of arrange them across here.  And actually before we even start,   [3:31] we've got a pretty tight range on what the average  ratio can be. Because the highest it can be is if   [3:37] boom, straight out of the gate, you flip a heads.  You've now got more tails than heads as required   [3:42] and it's 100% 100% heads. It's the highest  possible ratio. Or we could have like, you know,   [3:48] thousands of flips before eventually we have  more heads than tails. And when that happens,   [3:54] it will have just because there's so many just  gone over 50%. So really our range is 0.5 to one.   [4:02] Because we're calculating pi on four,  it means we've already narrowed pi down   [4:07] to between two and four, which you know, compared  to some historic pi days, we're doing pretty good.   [4:16] Now, what if we didn't get head straight  away? What if the very first flip was tails?   [4:20] Well, now we're going to have to keep going.  And the shortest sequence it could be now is   [4:24] three flips. It can't be two because  the best case scenario is we get heads,   [4:30] right? And but now it's 50/50. Has to be more  has to be greater than 50%. So potentially   [4:37] another heads. So now that's the Whoops. Shortest  sequence where it goes tails, heads, heads, stop.   [4:46] And that's a well, I guess that's a a half time a  half times a half. That's a half cubed probability   [4:52] of happening. And the ratio is two out of three.  But what if we didn't get that second heads?   [4:59] The next shortest would be five flips. So  for us to keep going in the first place,   [5:04] that would have to be tails there. Okay. And then  the next one will Oh, it has to be two more heads,   [5:12] right? Cuz we need to get it needs to be three  out of five heads for us to stop after five.   [5:17] So it would look like that. There it is. Okay.  Next shorter sequence is five. It ends on when   [5:22] we flip this heads. And that's the one that  tips us over to more heads than tails. So the   [5:26] probability of this sequence happening half times  a half times over five of them half the power of   [5:31] five. We can add that in and the ratio is 3 out of  five. Great. So we've Oh, hang on. Wait a minute.   [5:38] Yeah, this one works. But so does so is this  one. That's also a perfectly valid sequence.   [5:45] That's five long and would end at the same  point exactly when we flip that one. So there's   [5:51] I'll pick that up later. There's I can replace  it. So there's there's two of them. Okay, so now   [5:57] for each run of coins, we need the probability, we  need the ratio, and we need how many options there   [6:04] are. So we multiply this one by two. Let's have  a go at seven. Right, I've set us up seven spots,   [6:12] and we're going to think about what sequences  could possibly end at the seventh flip. And   [6:16] by end, it means that has to be us flipping a  head because that's the point at which we have   [6:21] more heads than tails and we stop. And at no point  before then can we have had more heads than tails   [6:26] otherwise we would have stopped including the very  first flip. There has to be a tails otherwise we   [6:30] would have stopped on the heads. The second one  could be heads or tails. We'll come back to that.   [6:35] Let's start by the case where we flip three tails  first. So tails are way out in front and then   [6:41] heads come slamming back and they get it right at  the end because four out of seven is the point at   [6:49] which this one means we've got more heads and  tails. So that's one. Write that down. However,   [6:55] this third tails here, that could happen later.  We could have that one was a heads and that one   [7:00] was a tails. That would work nicely. We can move  it further. That's two. If you're counting, we can   [7:05] move it down again. That could be uh heads. That  could be the tails. We can't do it again, however,   [7:12] because if this was heads and that was tails,  it doesn't work because we've already now look   [7:18] at that. Two tails, three heads, we would have  stopped. So, we only get those two extra ones.   [7:23] So, now we're up to uh three alto together. Now,  the other case was if that was a heads there.   [7:30] Now, if that's a heads, this one can't  be heads cuz otherwise we'll have more   [7:34] heads than tails. It's got to be tails like  that. And then that's still heads over there.   [7:39] And then these can go either way. This is either  a heads than a tails or it's a tails than a heads.   [7:45] Both of those work. You can't delay it any  longer. So, that that's five. If you want to   [7:50] pause and go through that yourself, you're very  welcome to. I spent a long time in my notebook,   [7:55] which I'm pointing down here because I've still  got all my This was me trying to work it out   [7:58] the other night, and I got all these sketches  of me going through being like, "Oh, what do I   [8:04] get in the sequence of heads and tails and tails  and heads? There's my there's me counting five,   [8:09] and I was right." So, I was able to fill that into  the table. And the next one, we could do it for   [8:15] nine. There's 14 ways to do it. I didn't bother  working that out. I put the sequence of 125 into   [8:26] the online encyclopedia of integer sequences and  it was all like, do you mean the Catalan numbers?   [8:33] And I was like, turns out I do. So why the  Catalan numbers? Well, to get my head around it,   [8:40] I then drew a diagram which I'm going to recreate  for you very quickly here on my whiteboard   [8:45] where I thought, you know what? Let's represent on  a kind of tree diagram. If you get a tails, you go   [8:51] down. If you get a heads, you go up. I had to roll  that in around the dog so I didn't hit the dog.   [8:57] And the goal is to end up above water. Very  simple. So, you start here on the surface   [9:03] and then if your first flip is a heads, you're  high and dry, you stop. If it's a tails,   [9:10] you're down here. To clarify, when  I mean above water, we stop flipping   [9:15] once we're one above this blue line. Because  if tails moves us down and heads moves us up,   [9:21] being one above our starting point means we've  now had more heads than tails. And then I just   [9:27] expanded the tree diagram because the next  one would bring you back up to the surface.   [9:32] This one would bring you even further below the  surface. Then you've got a chance to get out here   [9:37] heads. And there's only one way that that's  one way to do that. There's one way to do that,   [9:42] but there are multiple ways. If you go up here  next or down there and then up there and then out,   [9:51] then if you count that, you're like, "Oh, actually  there's two ways because I could have gone all the   [9:53] way down and all the way back and out or down, up,  down, up and out." And so if you start building up   [9:59] this diagram of all the ways you can flip  heads and tails and all the places you can end   [10:06] up and all the times that you break the  surface and escape and then you got to   [10:11] count the number of paths. Ah, you know what this  is reminding me of. But if we flipped it over,   [10:19] it's Pascal's freaking triangle. If you'd like  to learn more about Pascal's triangle and the   [10:23] Catalan numbers, my friend Sophie Mlan already  has a fantastic number file video all about it. I   [10:28] highly recommend you check that out. And it works  very neatly because Pascal triangle is effectively   [10:33] counting the number of ways you can get to any  given point. And we can use the Catalan numbers   [10:37] to normally cross over in the middle. Ah, it's  all it's really nice. Check out Sophie's video.   [10:43] But for our purposes, we're just going to  use the fact that the Catalan numbers counts   [10:46] the number of possible head or tail sequences.  Right now we're going to put it all together.   [10:52] So we can take our table from before and put it  into a generalized form. Catalan numbers start at   [10:58] n equals 0. The zeroth Catalan number which is  1. So we're going to use counting from zero.   [11:05] And the formula in general is going  to be 1 / 2 to the power of 2 n + 1   [11:12] multiplied by the nth Catalan number multiplied  by n +1 over 2 n + 1. That's just what we had in   [11:21] the table. But now you put in whatever value of  n and you get the next term in the series. And so   [11:26] we want to sum these from n equals z up infinitely  many of them. Then we get some result. And we do.   [11:35] I wrote down here last night. You can see there  was my terrible attempt at that tree diagram. Um,   [11:39] and over here next to it, I've written the formula  for the catland numbers. 1 / n +1 multiplied   [11:46] by 2 n choose n. And you can put that in terms  of factorials. We just substitute that in.   [11:53] And now we have one big chunky equation that  gives us each of the terms from n equals z   [12:01] all the way up. We just got to work out how we  turn that into pi. Okay, now we just need some   [12:09] kind of substitution or a way to rearrange  this to get closer to pi. What's that noise?   [12:17] It's arc sign. It's the inverse  function of sign that can be written   [12:23] as a series. Look at that. Isn't that amazing? I  mean, okay, look, here's the thing. I can't derive   [12:29] everything from first principles. It'll be a very  long and I'm aware of the things I'm about to say   [12:34] boring video. So at some point you've just got to  take something on faith and we're going to use the   [12:40] series expansion of aride. If you want to look  up how it's done, you can. In fact, it involves   [12:45] binomials and once again Pascal's triangle. Lovely  bit of mathematics. That's now your problem. All   [12:52] I'm saying is doesn't that look similar? In fact,  instead of ark sine of x, we could do ar sign of   [12:59] one. Just put that in. Why not? And that means the  x becomes one. That whole thing vanishes. And it   [13:05] looks pretty much exactly like what we had before.  In fact, it's just twice as big. It's two times   [13:14] whatever the average ratio of heads to tails is  in our previous calculation. And what's the arc   [13:20] sign of one? The inverse sign of one. What value  gives you one when you put it in sign? It's 90°.   [13:27] It's pi on 2. So pi on 2 equals twice the average.  The average is pi on four. It's still making me   [13:35] angry. I mean, here's the thing. We're not  surprised that if you flip a coin lots, the   [13:42] dogs come over to see why I'm getting emotional.  Uh, we're not surprised that stopping lots of   [13:48] different length sequences of flips and adding  them together gives us a series. That's what   [13:52] we'd anticipate and we're not surprised that you  can represent pi with an infinite series. That's   [13:58] classic pi. But I expect them to be separate  things. What stuns me is that one of the series   [14:06] for pi happens to match a series for flipping a  coin. It's ridiculous. I'm not happy about it.   [14:16] Thank goodness I got my therapy dog right here.  Oh, who's a good dog? This ridiculous pi coin fact   [14:22] was discovered last year by a mathematician I know  named James prop. And James is going to put up a   [14:27] blog post for this pi day going through all the  mathematics behind it. So I'll link to that below.   [14:32] You can check it out if you want to go through  the detail. It's even a bit of calculus in there   [14:37] if you're into that kind of thing. But  for me normally my problem would be oh I'm   [14:42] like a such a good fact. I need to do a thing  for pi day. I could sit here and flip a coin   [14:46] over and over and over again and calculate pi by  hand. But this time, I don't have to because it   [14:52] turns out it's already been done by my longtime  collaborator, past Matt. So, here's why past Matt   [14:59] was flipping a coin 10,000 times. I've had this  longunning project in my creator calculate how   [15:06] thick a three-sided coin would have to be, which  is a coin where it's equally likely to land heads,   [15:13] tails, or edge. And I've talked about this  before. or it's been on hold for a long time,   [15:18] but I found the current state-of-the-art.  But I realized the state-of-the-art was a   [15:23] single paper. In fact, to this day, if you go to  Wikipedia and look at the entry on coin flipping,   [15:28] the one citation for landing on edge is the  paper probability of a tossed coin landing on   [15:35] edge from 1993. So, I thought I would recreate  their experiments and I'll do my own experiment   [15:44] in an attempt to investigate that.  Now, I never got around to analyzing   [15:48] the data. I did recreate their experiment by  sliding the pound coin, which is what they used,   [15:54] off a horizontal surface a thousand times. Then,  I did my own 10,000 flips. I'll link to it below   [16:01] if you want to have a look at the data. You can  analyze it yourself. Uh the big reveal 14 times   [16:07] landed on its edge 14 times. Now this whole  experiment was a complete waste. It became   [16:13] a whole section in my book humble pie. But the  footage the footage I never had a reason to use   [16:20] until now. Until I wanted to calculate pi.  So here's my big spreadsheet of data. I'll   [16:26] link to this below if you want to check it out  for yourself. It's got the exact time I flipped   [16:29] every single coin. Wow, that was a late night.  And then over here, started heads, landed heads,   [16:35] every single landing one. And that's just my kind  of count count if 14 edges. Ah, good times. Now,   [16:43] we need to analyze this, which means we got  to get into Python. And I thought it might be   [16:47] fun to write the code. So, all I'm doing here is  I'm using open py. That's Python for Excel files.   [16:55] I've I've I've set up the name of the file and  everything. We want to count how many sequences   [17:02] we've been through and that starts with  zero of them. I try to have remotely   [17:06] useful names. That's also zero. And then for each  one, we need to count two things. How many heads   [17:14] and how many flips? What are  we going to do with edges?   [17:20] Let's ignore them. [laughter] Let's say they  don't they don't count. They don't count. It's   [17:26] got to be heads or tails. Lowerase H or T. So what  we'll do now is if the flip result equals heads   [17:38] then we increment head count. So that goes up by  one. And then if flip result doesn't equal e then   [17:55] that's our total number of flips. Okay. So, all  I've done there is each time we flip it, if it's   [18:00] heads, we add to the running head count. If it's  not edge, we add to the running total number of   [18:06] flips count. Great. Now, we got to check if we've  hit the end of a sequence. So, if that happens,   [18:13] we want to work out the ratio of heads to tails in  that run. So, we're going to say this ratio equals   [18:19] uh headcount divided by flip count. I could  do all this in one big long chunky line.   [18:25] I like to split things out because it makes my  life a little easier to try and read it. So,   [18:29] I'm going to take running ratio total add on  this ratio. And we've had one more sequence.   [18:35] So, uh what do we call our sequence count? Count  sequences. Well done. Pass mat always there for   [18:42] me. So, we add one onto that. Now, we want to  reset cuz we're going to start another run. So,   [18:48] flip count and head count now get set back to  zero. Okay, that should be everything. Oh, that's   [18:55] I can't increment flip result. That's  what I It's flip count. What a dingus.   [18:59] Okay, that fixed. I kind of want to check it's  working before we get the big result. Let's run   [19:07] it first without calculating the result. That's  the big reveal. Each time we'll print the result   [19:14] and then down here we'll print what we think  the ratio was. Okay, so now we can run it.   [19:21] It'll do that for all 10,000 flips. make sure it  functions and make sure it's doing what we expect.   [19:26] You never know with code. It's like if you just  run it without making sure you've gone through to   [19:32] make sure everything's working properly. It's  a very opaque process which makes me nervous.   [19:37] Ah. Oh, there it is. It ran. Oh, these  are long runs. Oh, okay. It is working.   [19:42] So, that was a super long run. Look at it. And  when it finally ended, it was just over a half.   [19:48] Next one was a heads. So, it was one heads was  one. So this was a total of 1 2 3 4 5 6 7 8 9   [19:57] 10 11 flips of which one two three four five six.  So yeah, so it was five and five. One more heads   [20:09] tipped it over to six and five. It stopped and  ratio 54.54%. Okay, I'm happy the code is working.   [20:17] I'm going to undo that one. Now once  it finishes running, let's just print.   [20:27] Should we do it all at once? Should we just print  pi? Let's just print pi. You know what? Let's do   [20:35] pi val equals running ratio total divided by count  sequences. So that's the total of all the ratios   [20:44] divided by how many there are. That gives us  the average. And then we multiply that by four.   [20:49] And then we print pi val. So this is it folks.  This is the value of pi for pi day 2026.   [21:00] We're going to zoom. Let's get right in. I know  that's messy, but I want a big number. Okay.   [21:04] Ready? Okay. Here we can't see producer Nicole is  just out of shot over there. Very excited. Camera   [21:13] person Alex is over there wildly indifferent.  And now we run the code. 3.2266. [music] [21:24] That's better than I was braced for  cuz it converges so slow. Wow. 3.2266. [21:35] For everyone who keeps a running record of  my successes and failures, write that down.   [21:42] That's good stuff. Obviously, while I was  flipping a coin 10,000 times, I had a bit of fun.   [21:47] did some ridiculous bits to camera and then I  thought, you know what? Why don't I try this   [21:51] in a fake collaboration where a coin  unexpectedly keeps landing miraculously   [21:57] on its edge. In a previous video, I said there  was a trivial chance when you flip a coin   [22:02] of it landing on its edge. And even though you  can balance a coin on its edge, it's a common   [22:07] misconception that that can happen when it's  in motion. If you actually flip a real coin,   [22:13] it lands on a physical surface. It will  never land on its edge. And to prove why   [22:18] that's impossible, you need some very nice  mathematics, some interesting physics,   [22:23] and some things you might not know. The first  step, however, is just to actually flip a coin and   [22:29] take a close look at what happens. If you watch  what actually happens when you what? Oh, come on. [22:41] Okay. Okay. All right. Okay. About about the  collaboration. I got it. It landed on its edge.   [22:47] No, you didn't. No. Seriously. Seriously. I  flipped it. That's not possible. First take   [22:51] I landed on its edge. Is we pro? We No, I know. I  know. I know what we proved, but I'm just saying   [22:56] it happened. Do it again. There's no Look,  there's no way. What? You You show me then. [23:07] See? No. Yes. Wait. No. Yeah. I don't  care what your physics says. It can't   [23:12] happen. I know. I know. But I did  it again and it's bang on the edge.   [23:17] Okay. You're kind of the worst  time. It's ended on the edge.   [23:23] I've got some terrible news about our collab.  [laughter] It's been literally minutes. [23:32] See you later. [23:38] Yes, Steve Mold and Tom Scott did stand around  waiting for as long as it took for me to get that   [23:45] coin to land on an edge. Absolute legends. Sorry  it took me 8 years to get it out, folks. Uh but   [23:51] here we are. And now back to Modern Matt for the  final wrap-up. And we're done. Ah, it's so great.   [23:59] 2026 literally 26 in the digits of pi. So write  that down for the next 12 months. Pi equ= 3.2266.   [24:08] Ah, fantastic. Now, some updates for the people  who watch right till the end of the video. Yes,   [24:14] we will do pi by hand again. We've done some  testing. We got a new method. We've done a bunch   [24:20] of research. We got a whole team on it. It's going  to take it's going to take so many people for so   [24:25] long. I'm going to need so many volunteers that  are all prepared to sit there for a while. And we   [24:31] haven't really got a plan for that. We're trying  to work out the best way to do it. If Moonpie is   [24:36] a success on the first launch, the leftover  funding from that will go into Pi by hand,   [24:41] which means we can probably do it at the scale  it requires. I promise I will give you at least   [24:47] 12 [music] months warning if you want to come  along and be part of the pie by hand calculation.   [24:52] Link in the description for the sign up form.  I will keep you in the loop and I will tell you   [24:56] more than a year in advance when we're going to  attempt it. So don't panic. You will be there.   [25:01] Moonpie, the update is out. That's a lot of fun.  Go check it out. Link to it below. Hopefully we   [25:08] will launch um at some point this year. Um we'll  see what happens. Uh and [music] just in general,   [25:15] thanks for watching the videos. Oh my goodness.  This is a wonderful tradition calculating pie.   [25:19] And I couldn't have done it without Passmat.  Big thanks to Passmat. Um thanks to Sophie Mlan   [25:25] for all things Catalan numbers. Jim Prop for  discovering this ridiculous thing. I'll check out   [25:31] uh I'll link his blog post. You should check that  out. Uh, and of course, Steve Mold Tom Scott for   [25:36] for waiting for a ridiculous amount of time for  a dumb joke that I didn't release for 8 years.   [25:43] That's a pretty accurate representation of what  it's like um to be friends with me. Um, so that's   [25:49] it. Thanks. Thanks for supporting the videos.  Thanks for everyone on Patreon. Uh, you know,   [25:54] I feel like Pi Day is like uh end of one year.  You know, you get like financial years and school   [25:59] years. I run on pi years. So, that was the end of  the 2025 2026 Pi Day season and now we're going to   [26:07] go uh into the next one. And so, um that's it. So,  I guess we don't need this coin until next time. [26:22] Oh, no. [laughter] Oh. Oh, that's so unfair.