 Hello everyone and welcome to another episode of Code Emporium where we are going to play some bingo. I have 50 prizes that I want to give you, the audience. Not really, no, it's just for the sake of the video. And so I decide to do it with a game of bingo. But how do I set up this game so that I only have 50 winners? And that's how we're going to use Monte Carlo simulations to figure that out. And so in this video we're going to describe how bingo works, what are things that we need to look out for, like parameters and assumptions, and then actually code simulations out. So with bingo everybody gets a card that kind of looks like this a five cross five grid with numbers arranged from like one to 90. They're non repeating. And there'll be this teller that basically picks up random numbers, probably like some fixed number of them, like five or 10 numbers, and we'll start calling them out. And as the numbers are called out, you just need to put your markers on the numbers that you have that are being called out. And after all the numbers have been called, we're going to see if you have a five in a row or five in a column or five on a diagonal, then you win the game. If you not, then well, you're not a winner. And unfortunately, you get nothing. But when playing this game right now, there are a couple of assumptions and parameters that we need to know. And the first is how many players are playing the game, then how many calls are we actually making during the game that is during the game. There's the teller and how many numbers are they calling out. Then we have the fact or rather assumption that when you're making calls, all of these numbers are generated randomly between one through 90, just an assumption that we're making. And it seems to be a pretty safe assumption to now that we got that out of the way, let's generate some data. So first, this is how we would like generate the board. So this here is an example bingo board of a five cross five grid. This could be for like one player and I'm randomly generating calls. So these are the numbers that are called throughout the game. Now for this board, if these calls were made, this Boolean matrix would represent the like how the board would be filled up. So essentially it's saying, okay, 81 over here is true, which means that it was called out to and that is the case here. It's present here. Same with this number right here, which is 58, which was indeed called out to. And so as a player, you would just hear your numbers and just like fill out the board. Now, once these 20 calls are made, you have to kind of determine if this person has one or not, right? And for that, well, we just need to see if they we just need to check all the rows, which we do here, we need to check all the columns, and then we need to check both diagonals. If at least one of them has a five or like all five of them are true, then the player is one. In this case, this player only has a maximum score of three, which I think is along this diagonal right here, true, true, true, false, false. But this is an example of a player or a board which has not won the game even after 20 calls. But again, this is for a single player. And what we're going to be assuming when we're actually running a simulation is like, let's say that they're 500 players and we make the same 20 calls. And let's say that we're running 500 simulations. A simulation is essentially just a run of the entire game, like a world of possibilities what of what can happen. So this is one simulation is one world. So in one simulation, we will generate like the five cross five grid, we will hand out bingo cards to all 500 players, we are going to make a random call of 20 numbers. And then we are going to determine the winners for that. So let's say that there's like 50 people that win this one, for example, well, that's for one simulation. And we want to run this simulation, we want to run like this another 499 simulations, and then average it all out average our winning average the number of winners throughout with averages, we get a more consistent, realistic number of what you can potentially expect. And that's kind of the gist of like what we're doing entirely here, right? So in this case, I'm running 500 simulations with like 500 players and 20 and doing 20 calls. And if you actually look at how the win percentages, we're computing win percentages, by the way, we can compute number of winners, of course. But you know, if you want to increase the number of players to instead of 500, make it 1000 win percentages just become easier to deal with for this particular simulation or range of simulations, you could see how like over time, the, you know, in the beginning, it's a little, it's a little spiky, the total, you know, mean percentage of people that have won. But then after like the 250th simulation, it kind of flattens out, which means that on average, you can kind of take this to be the case that's like 1.01% or somewhere between one and 1.1% of the people win, right? And that's kind of what we see here. So win percentage after 500 simulations is 1.01%, which means like five winners since we have like 500 people playing. But I have 45 more prizes to give out and well, we can do better than this. We can probably extend the game a little bit, try to see what we can change. Now, the main parameters that we mentioned here are, what are they? They are the number of players playing and also the number of calls that we're making. Well, typically that you can't just increase the number of players. So it's not so easy just to get like 500, we can get 5,000. So instead, what we can do is we can try to increase the number of calls that are made during the game. And this could hopefully help increase the number of prizes and number of winners in the game. Let's see how sensitive it is to calls. And I have this title called sensitivity over here. So let's vary the number of calls and see how the win percentages shake out. So in this case, for every single simulation, I'm basically generating boards for all players. I'm going to generate 50 though, like 50 calls, not just 20. And then I'm only going to use like the first five, the first 10, the first 15, the first 20 and so on in order to determine the winners for each case. So for every run, we're going to have like 5, 10, 15, 20, 25 calls and for each of those, we're going to determine the number of winners or the percentage of winners. And so what we can do with that information is create a graph that looks like this, where you see if we had made 20 calls, we see that 1% of people win, which is kind of what we simulated, you know, initially. But if we had made 25 calls, you can see that that number goes from like 1% to 5%. If we make 30 calls, it's almost a 10 times increase over, you know, if we had made 20 calls. So just adding like calling more numbers throughout the game, dramatically or almost exponentially like increases the number of people who win the game. And so just increasing the number of calls is probably the best thing that we can do here. Like we can make statements like if we made 30 calls instead of 20 calls, the number of winners increased by over 8 to 9%. And so if we had made 30 calls, the number of winners would have been around 54, which is kind of around what number of prizes that I wanted to give out. So if I was playing a game of bingo and there's 500 of you actually playing, and I'm the one hosting the game, I could expect 54 people would win the game if I call out 30 numbers. And well, that actually helps a lot, right? So I would say this is the main chunk of the code pretty small, pretty simple to follow. Now, I would say as an exercise, why don't you try varying the number of players and seeing how the win percentage changes. So instead of 500 players, try to make it 1000 or try to make it 2000. And let me know what you see. It's pretty interesting what you see there too. Also vary the number of calls to see how the win percentage has changed. This is a small example, but you know, you can try playing around with even more calls and more simulations. The problem here of using more simulations is that, you know, it can take a really long time. So you want to try to use, try to perform as many simulations as possible, take the average of that so that it becomes as accurate as possible. But if you, but trying to do too many simulations, because it just won't finish. And so that's kind of the gist of what I have today. So in conclusion, these are, by the way, Monte Carlo simulations. It's a really nice way to make approximations through trials that is through simulations, and we can apply it to almost like any other fields. Like if you, if you think that it's easier to just run simulations and just get like different scenarios of the real world and aggregate them, Monte Carlo simulations will do the job for you. And that's all I have today. So thank you all so much for watching this quick video. Please do subscribe. Please join the discord. There is so much more that we are talking about on the discord server. So it'd be lovely if you would join as well. And we can talk more about bingo there. That's all from me and I will see you in the next video. Bye bye.