Sign in

Monty Hall 21 Blackjack

>>> Register here <<<

  1. Il Paradosso Di Monty Hall ( 21 Blackjack)
  2. Monty Hall 21 Blackjack Rules
  3. Problema De Monty Hall 21 Blackjack

Mimic process of picking at random we use the sample().

The movie ‘21’ is the story of MIT students who ‘count cards’ to improve their probability of winning the card game Blackjack at casinos. Not surprisingly, this movie has a lot of mathematics in it. Most obvious is the ‘counting of the. The movie ‘21’ is the story of MIT students who ‘count cards’ to improve their probability of winning the card game Blackjack at casinos. Not surprisingly, this movie has a lot of mathematics in it. Most obvious is the ‘counting of the. 21 Blackjack Monty Hall, roblox script pastebin gamepass, himdsgavl slot, dotty’s casino billings heights.

replicate() function can be used to repeat a task any number of times.

Monte Carlo simulatin gave a very good approximation.

expand.grid() gives all the combinations of two list

Kevin Spacey and the character, Ben Campbell, from the movie ‘21’ explains the Monty Hall ‘Game Show Host’ problem. This is a very good description of variab. อธิบายปัญหาความน่าจะเป็นสุดคลาสสิค Monty Hall Problem (1975) จากภาพยนตร์เรื่อง 21 แก้สมการได้ง่ายๆด้วย Probability Axioms ข้อที่สอง.

We are going to be using the combination() and permutation() functions from the gtools package.

The permutation functions computes for any list of size n all the different ways we can select R items.

Optionally we can add a vector to this function that defines the range of digits. The code below samples 5 random 7 digit phone numbers out all possible phone numbers.

To compute all possible ways that we can choose 2 cards when the order matters, we simply type the following piece of code.

The above code is the R version of the multiplication rule.

[Pr(Amid B)=frac{Pr(A and B)}{Pr(A)}]

Now, what if the order does not matter? For example, in blackjack, if you get an ace and a face card or a 10, it’s called a natural 21, and you win automatically. If we want to compute the probability of this happening, we want to enumerate the combinations, not permutations, since the order doesn’t matter.

So if we get an A and a king, king and an A, it’s still a 21. We don’t want to count that twice. So notice the difference between the permutations functions, which lists all permutations, and the combination function, where order does not matter. This means that 2, 1 doesn’t appear because 1, 2 already appeared. Similarly, 3, 1 and 3, 2 don’t appear. So to compute the probability of a natural 21 in blackjack, we can do this.

How often do you get aces and facecard

We can also use a Monte Carlo to estimate this probably. In this case, we draw two cards over and over and keep track of how many 21’s we get. We can use the function sample to draw a card with a replacement like this.

Suppose you’re in a classroom with 50 people. If we assume this is a randomly selected group, what is the chance that at least two people have the same birthday? Although it is somewhat advanced, we can actually deduce this mathematically, and we do this later, but now, we’re going to use Monte Carlo simulations. For simplicity, we assumed that nobody was born on February 29th.

This actually doesn’t change the answer much. All right, first, note that birthdays can be represented as numbers between 1 and 365.

So a sample of 50 random birthdays can be obtained simply using the sample function, like this.

To check if, in this particular set of 50 people we have at least two with the same birthday, we can use the function duplicated, which returns true whenever an element of a vector has already appeared in that vector.

So here’s an example. If I type duplicated 1, 2, 3, 1, 4, 3, 5,

And in the case that we just generated, we actually do have this happening. We did have two people, at least two people, with the same birthday. We get true. Now, to estimate the probability, we’re going to repeat this experiment. We’re going to run a Monte Carlo simulation over and over again. So what we do is we do it 10,000 times.

Apps offline free
Apps offline free

We use the replicate function like this.

And when we’re done, we get that the probability of having two people, at least two people, with the same birthday in a group of 50 people is about 0%.

Were you expecting this to be so high? People tend to underestimate these probabilities, so it might be an opportunity for you to bet and make some money off of your friends. To get an intuition as to why this is so high, think of what happens as you get close to 365 people. At this stage, we run out of days, and the probability is 1. In the next video, we’re going to actually compute this probability for different group sizes and see how fast it gets close to 1.

Say you want to use what you’ve just learned about the birthday problem to bet with friends about two people having the same birthday in a group of people. When are the chances larger than 50%? Larger than 75%? Let’s create a lookup table. We can quickly create a function to compute this for any group. We write the function like this. We’ll call it compute_prob, and we’ll basically make the calculations for the probability of two people having the same birthday.

Well, we use a small Monte Carlo simulation to do it. Now that we’ve done this, we want to compute this function, we want to apply this function to several values of n, let’s say from 1 to 60. Let’s define n as a sequence starting at 1 and ending at 60. Now, we can use a for loop to apply this function to each value in n, but it turns out that for loops are rarely the preferred approach in R.

In general, we try to perform operations on entire vectors. Arithmetic operations, for example, operate on vectors in an element wise fashion. We saw this when we learned about R. So if we type x equals 1 through 10, now X is the vector starting at 1 and ending at 10, and we compute the square root of x, it actually computes the square root for each element.

Equally, if we define y to be 1 through 10, and then multiply x by y, it multiplies each element 1 by 1–
1 times 1, 2 times 2, et cetera.

So there’s really no need for for loops. But not all functions work this way. You can’t just send a vector to any function in R. For example, the function we just wrote does not work element-wise since it’s expecting a scalar, it’s expecting an end.

This piece of code does not do what we want. If we type compute prob and send it the vector n, we will not get what we want. We will get just one number.

What we can do instead is use the function sapply. sapply permits us to perform element-wise operations on any function. Here’s how it works. We’ll define a simple example for the vector 1 through 10. If we want to apply the square roots of each element of x, we can simply type sapply x comma square root, and it’ll apply square root to each element of x.

We don’t need to do this because square root already does that, but we are using it as a simple example. So for our case, we can simply type prob equals sapply n.

n is our vector

and then the function we define compute_prob. And this will assign to each element of prob the probability of two people having the same birthday for that end. And now we can very quickly make a plot. We plot the probability of two people having the same birthday against the size of the group.

Now, let’s compute the exact probabilities rather than use Monte Carlo simulations. The function we just define uses a Monte Carlo simulation, but we can use what we’ve learned about probability theory to compute the exact value. Not only do we get the exact answer using math, but the computations are much faster since we don’t have to generate experiments.

We simply get a number. To make the math simpler for this particular problem, instead of computing the probability of it happening, we’ll compute the probability of it not happening, and then we can use a multiplication rule. Let’s start with the first person. The probability that person 1 has a unique birthday is 1, of course.

Now let’s move on to the second one. The probability that the second person has a unique birthday given that person 1 already took one other day is 364 divided by 365. Then for a person 3, given that the first two people already have unique birthdays, that leaves 363. So now that probability is 363 divided by 365.

If we continue this way and find the chances of all, say, 50 people having unique birthdays, we would multiply 1 times 364 divided by 365, times 363 divided by 365, dot dot dot, all the way to the 50th element.

Here’s the equation: [1timesfrac{364}{365}timesfrac{363}{365}cdotsfrac{365-n+1}{365}]

Now, we can easily write a function that does this. This time we’ll call it exact_prob. It takes n as a argument, and it computes this probability using the simple code. Now we can compute each probably for each n using sapply again, like this.

And if we plot it, we can see that the Monte Carlo simulations were almost exactly right.

They were almost exact approximations of the actual value. Now, notice had it not been possible to compute the exact probabilities, something that sometimes happens, we would have still been able to accurately estimate the probabilities using Monte Carlo.

In practice, we won’t know what the answer is, so we don’t know if our Monte Carlo estimate is accurate. We know that the larger the number of experiments, we’ve been using the letter B to represent that, the better the approximation. But how big do we need it to be? This is actually a challenging question, and answering it often requires advanced theoretical statistics training. One practical approach we will describe here is to check for the stability of the estimate.

Here’s an example with the birthday problem. We’re going to use n <- 22. There’s 22 people. So we’re going to run a simulation where we compute or estimate the probability of two people having a certain birthday using different sizes of the Monte Carlo simulations. So the value of B going to go from 10, to 20, to 40, to 100, et cetera. We compute the simulation, and now we look at the values that we get for each simulation.

Remember, each simulation has a different B, a different number of experiments. When we see this graph, we can see that it’s wiggling up and down.

That’s because the estimate is not stable yet. It’s not such a great estimate. But as B gets bigger and bigger, eventually it starts to stabilize. And that’s when we start getting a feeling for the fact that now perhaps we have a large enough number of experiments.


The additional rule tells us that the probability of A or B, we’re going to have to make this calculation now, because you can get to 21 in two ways. You can get either a face card and then an ace. Or you can get an ace and then a face card. The additional rule tells us the probability of A or B is the probably of A plus the probably B minus the probability of A and B.

To understand why this makes sense, think of a Venn diagram. If we’re computing the probability of this whole thing happening, A or B, we can add the blue circle plus the pink circle, and then subtract the middle because we have added it twice by adding the blue plus the pink.

So now let’s apply it to the natural 21. In the case of natural 21, the intersection is empty. Since both hands can’t happen, you can’t have both an ace and then a face card, and then at the same time have a face card and then an ace. Those two things can’t happen at the same time. So this will be a very easy application of the addition rule. The probably of an ace followed by a face card we know is (frac{1}{13}timesfrac{16}{51}). And the probability of a face card followed by an ace is (frac{16}{52}timesfrac{4}{51}). These are actually the same, which makes sense to the symmetry. These two values are actually the same. In any case, we get the same result that we got before for the natural 21, which is about 0.05.

We’re going to look at one last example from the discrete probability. It’s the Monty Hall problem. In the 1970s, there was a game show called “Let’s Make a Deal”. Monty Hall was the host– this is where the name of the problem comes from. At some point in the game, contestants were asked to pick one of three doors. Behind one door, there was a prize. The other two had a goat behind them. And this basically meant that you lost.

If the contestant did not pick the prize door on his or her first try, Monty Hall would open one of the two remaining doors and show the contestant that there was no prize behind that door. So you’re left with two doors, the one you picked and one door that you do not know what’s behind it. So then Monty Hall would ask, do you want to switch doors? What would you do? We can use probability to show that if you stick to the original door, your chances of winning a car or whatever big prize is 1 in 3. But if you switch, your chances double to 2 in 3. This seems counterintuitive. Many people incorrectly think both chances are 1 in 2, since there’s only two doors left and there’s a prize behind one of them. You can find details, explanations– we’re going to provide links of the mathematics of how you can calculate that this is, in fact, wrong, that you have a higher chance if you switch. But here, we’re going to use a Monte Carlo simulation to show you that this is the case. And this will help you understand how it all works. Note that the code we’re going to show you is longer than it needs to be, but we’re using it as an illustration to help you understand the logic behind what actually happens here. So let’s start by creating a simulation that imitates the strategy of sticking to the same door.

Let’s go through the code. We’re going to do 10,000 experiments. So we’re going to do this over and over 10,000 times. First thing we do is we assign the prize to a door. So the prize is going to be in one of the three doors that we have created. Then that’s going to be in prize door. Prize door contains the number of the door with the prize behind it. Then we’re going to imitate your pick by taking a random sample of these three doors. Now, in the next step, we’re going to decide which door you’re shown. You’re going to be shown not your door and not the door with a prize. You’re going to be shown the other one. You stick to your door. That’s what you stick to. Nothing changed. All this that we did right above doesn’t matter, because you’re sticking to your door. So now we do this over and over again, and at the end, we ask is the door you chose, the one you stuck to, is that the prize door? How often does this happen? We know it’s going to be a 1/3, because none of this procedure changed anything. You started picking one out of three, nothing changed. And now, you are asked, is the one I picked the door? If we run the simulation, we actually see it happening. We ran it 10,000 times and the probability of winning was 0.3357, about 1 in 3.

Two teams, say the Cavs and the Warriors, are playing a seven game championship series. The first to win four games wins the series. The teams are equally good, so they each have a 50–50 chance of winning each game.

If the Cavs lose the first game, what is the probability that they win the series?

  • Assign the number of remaining games to the variable n.
  • Use the list function to create a list of game outcomes, where 0 indicates a loss for the Cavs and 1 indicates a win for the Cavs. Assign this value to the variable l.
  • Use the expand.grid function to create a data frame containing all the possibilities for outcomes of the remaining games.
  • Use the rep function within the expand.grid function to indicate the number of columns the results data frame should contain.
  • Use the rowSums function to identify which combinations of game outcomes result in the Cavs winning the number of games necessary to win the series.
  • Use the mean function to calculate the proportion of outcomes that result in the Cavs winning the series.

Confirm the results of the previous question with a Monte Carlo simulation to estimate the probability of the Cavs winning the series after losing the first game.

  • Use the replicate function to replicate the sample code for B <- 10000 simulations.
  • Use the sample function to simulate a series of 6 games with random, independent outcomes of either a loss for the Cavs (0) or a win for the Cavs (1).
  • Use the sum function to indicate which of the simulated series contained at least 4 wins for the Cavs.
  • Use the mean function to find the proportion of simulations in which the Cavs win at least 4 of the remaining games.

Two teams, (A) and (B), are playing a seven series game series. Team (A) is better than team (B) and has a (p > 0.5) chance of winning each game.

  • Use the function sapply to compute the probability, call it Pr of winning for p <- seq(0.5, 0.95, 0.025).
  • Then plot the result plot(p, prob).

Repeat the previous exercise, but now keep the probability that team (A) wins fixed at p <- 0.75 and compute the probability for different series lengths. For example, wins in best of 1 game, 3 games, 5 games, and so on through a series that lasts 25 games.

  • Use the seq function to generate a list of odd numbers ranging from 1 to 25.
  • Use the function sapply to compute the probability, call it Pr, of winning during series of different lengths.
  • Then plot the result plot(p, Pr).

R Core Team. 2018. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing.

Saw the movie 21 on Saturday. I have always been a fan of Kevin Spacey and this guy keeps impressing me with every one of his portrayals. Overall the movie was a bit too long. It was a two hour plus movie which could have easily been completed in about an hour thirty. Loved the part about the Monty Hall problem.

For the uninitiated, Monty Hall was a game show host on “Let’s make a Deal”. The problem goes something like this. “Given three doors, with a car behind one, and goats behind the other two, you choose door1, the host then opens up door 3 to show a goat and offers you an option to switch your choice. Is it to your advantage to switch? “. I initially thought that once the third door is opened, your probability of getting it right was 50–50. But apparently I was wrong. By actually switching your choice, you get a 2/3rd probability of winning the prize, as explained here. Being a bit of a math buff, I found that very interesting and non-intuitive.

Coming back to the movie, Kevin Spacey was the typical smooth talking conspiratory character. He has got that part down ever since Usual Suspects. Jim Sturgess was fresh and was quite comfortable playing either the geek or the high-roller. At the cost of repeating myself, the movie was just a bit too long. How many times does one have to see how Jim spends his money. Same BJ tables, same four moves, same laughter at winning money etc. The director could have spent more time on the mathematical aspects of the game, instead of repeating the Vegas scenes as many times. Overall its a good-to-watch movie, if you dont have to get anywhere else in a hurry. Have fun!

>>> Register here <<<