# Python!

Hello, thanks for checking out the Python portion of my blog!

Probability Puzzles

If you know of any fun probability puzzles, please feel free to contact me! I am constantly adding new puzzles and I would love to include them here.

There are quite a few puzzles at the end of this page that I have yet to provide a solution.

Note, the vast majority of these solutions where coded well before ChatGPT. I have found that ChatGPT can create these simulations in a matter of seconds with 100% accuracy.

If you are unfamiliar with the birthday paradox, see the Wikipedia article here.

Here I have broken the puzzle into two different parts.

Part I

Create a simulation to prove that a 50% probability of two people having the same birthday is reached with only 23 people.

Part II

A professor lines her students up in a single-file row and tells them that the first person to have a matching birthday of someone in front of them receives a passing grade. Which individual has the best chance of winning?

Simulating A Multiple-Choice Exam

Everyone can relate to taking an exam and finding yourself guessing at the answers more then what you would like.

Here we simulate a multiple-choice exam where you divide the questions into three probabilities of attaining a correct answer and determine a probability of achieving a desired score.

Weather in Probability Land

In Probability Land, on a sunny day there is an equal probability of the next day being sunny or rainy. On a rainy day, there is a 70% chance it will rain the next day, and a 30% chance it will be sunny the next day.

On average, how many rainy days are there in Probability Land?

How Many People Are Visible?

There are 5 people each with a different height. They all stand in a straight line, and you stand directly in front looking at them.

How many different arrangements of those 5 people are possible that would have exactly 3 people visible to you?

Find Your Seat: Airplane Probability Problem

You are running late in an airport and are in the very back of the line to board your plane. The plane seats fifty people. The first person in line forgot his seat number and chooses a seat at random when he enters the plane. Each subsequent person will sit in their assigned seat unless it is taken by someone else. If they find their seat already occupied, they will choose another seat at random.

If you are the last person to board the plane, what is the probability that you will get your assigned seat?

Coin Flipping Game

Your friend has a coin and asks you if you want to play a game:

“I will flip this coin until the number of heads flipped is equal to the number of tails flipped. Then I will give you a dollar for each time I flipped the coin.”

What are the chances that you play this game with your friend once and he pays you exactly eight dollars?

You need to settle a dispute by means of a coin flip.

The only coin available to you is an old wooden nickel and you are certain that it comes up heads more than 50% of the time. How can you be sure to have a fair contest that is based purely on chance by only flipping this coin?

Determine a solution to the riddle and demonstrate its accuracy via a simulation. Note, there may be more than one possible solution to this riddle.

How Many Visitors?

If my super fancy puzzle website averages 12 visitors a day, what are the chances of…..

Getting exactly 10 visitors a day?

Getting 10 or more visitors a day?

You will need to use a Poisson distribution to solve this problem.

Unknown Deck of Cards

You possess a deck with 50 cards that has an unknown and random number of red and black cards. What is the probability of drawing a red card from the deck?

Unfair Dice

You have 2 dice; 1 is fair and the other unfair. The unfair dice rolls a 6 50% of the time.

What is the probability of choosing the unfair dice if you randomly choose a dice and roll a 6?

Dealing An Ace

In poker, the first person to be dealt an Ace gets the role of dealer. Is the probability of being dealt the first Ace equal for all players?

Create a simulation to find out.

Get Out Of Jail

You are locked in a jail cell and demand to be released because you are innocent. The warden tells you he will release you if you can win 2 straight games of checkers. But you must play at least 1 game against the warden and 1 game against the sheriff. You know the sheriff plays a better game of checkers then the warden.

Do you have a better probability of winning if you play [Warden -> Sheriff -> Warden] or [Sheriff -> Warden -> Sheriff]?

Remember, the sheriff is a better checkers player then the warden, and you must win 2 straight games.

Pearly Gates

You die and arrive at the pearly gates of heaven. Unfortunately, the pearly gates are a set of three random doors. One door leads directly to heaven, one door leads to a 2 day stay in purgatory, and one door leads to a 3 day stay in purgatory. Once you are done with your stay in purgatory, you are back again to the pearly gates where the doors are again randomized.

What is your average stay in purgatory?

Favorite Child

You live in a society where female children are preferred over male children. By law, couples have to conceive children until they produce a female offspring. If their first child is male, they are allowed to have additional children until a female is born. Once a female is born, they are allowed no additional children.

What is the average ratio of females to males in this society?

Cell Reproduction

You are conducting a controlled experiment where you have a single cell. After a certain and reoccurring amount of time, the cell has a 2/5 chance of dying, 2/5 chance of being idle, and a 1/5 chance of replicating. After a replication, each cell has the same amount of probability.

Given 1 million trials, what is the maximum number of cells produced?

Shuffled Card Deck

Given a randomly shuffled deck of cards, where the numbered cards (1-10) are face value, the Ace is equal to 1, a Jack is equal to 11, a Queen is 12 and a King is 13.

What is the average number of cards in a shuffled deck that are in the correct numerical place?

For example, if an Ace is in the 1st, 14th, 27th, or 40th place in the deck, it would be considered in its proper numerical place.

Three Dice Rolls

The casino has an interesting new game.

You start with a bankroll of \$100 and place a \$1 bet on a number 1 through 6. You then roll three dice, and if any of the dice rolls match your original bet, you win the number of matching dice (\$1, \$2, or \$3), plus your original \$1 bet back. If you lose, your bankroll goes down \$1. You must play the game 100 times, and you keep the sum of your bankroll at the end of the 100 dice rolls.

What are the odds of winning?

Matching Cards In Two Decks

If you shuffle two separate decks of cards, what is the probability of the same card appearing in the exact same position in the two separate decks?

Estimation Of The Mean

At the Aces High Card Club, the top player wins her Skip-Bo games 59% of her time based upon 500 games.

1. Based upon an infinite number of games, what is the 99% confidence interval of the mean?
2. Assume a 59% percent win rate, run a simulation where you play the game 500 times and record the win percentage. What is your highest and lowest win percentages? What is the win percentage at the 99% and 1% percentiles?

Coupon Collecting

This problem is called the coupon collector’s problem.

A cereal is running a promotion where if you collect all 10 coupons, you win a prize. A coupon is only available if you buy a box of their cereal. What is the average number of box purchases needed in order to collect all 10 coupons?

Increasing Percentage Gamble

A casino has a new game. A gambler can bet \$10 and get a 1% chance of winning \$100. If the gambler loses, they can bet another \$10, and their chance of winning increases from 1% to 2%. After each loss, the gambler can bet \$10, and the chance of winning will increase 1%.

What is the average number of bets the gambler must place to win the \$100? Is this game in favor of the gambler or the casino?

Pitching a Complete Game

Your All-Star baseball pitcher has a 15% chance of pitching a complete game. After how many starts does the pitcher have a 90% chance of pitching a complete game?

Utilizing the average NBA shooting statistics from the 2022-2023 season, the three-point shooting success rate stands at 36.1%, while the two-point shooting success rate is 47.5%.

Run repeated simulations of a basketball game where one team solely attempts three-point shots, whereas the opposing team restricts itself to two-point shots. Each team is given exactly 90 shot attempts in each game. Conduct a comprehensive statistical evaluation of the ensuing results.

Simulating the Monty Hall Problem

Run a simulation of the Monty Hall problem.

Winning Percentage

Your favorite football team has the following pre-season estimated win percentages for their 12-game schedule. What is the most likely outcome for their final win total? The win percentages are 95%, 26%, 55%, 63%, 45%, 75%, 60%, 52%, 51%, 72%, 59% and 81%.

White Ball

Imagine a bag that contains a single ball, which has an equal probability of being either black or white. Now, add a white ball to this bag. At this point, the bag holds two balls: one white and another that could be either white or black, each with an equal chance of 50%. If you were to randomly draw one ball from the bag, what would be the likelihood that the remaining ball inside the bag is white, given that you’ve drawn a white ball?

Keep the Prize

As the host of a weekly dinner gathering that includes you and seven friends, you’ve come up with an interesting method to decide who will be the host for the upcoming dinner party.

After the meal, all attendees, including yourself, gather around a circular table. You, as the current host, initiate a game by flipping a fair coin. If the coin lands heads up, you hand the coin to the person sitting on your right; if it’s tails, you pass it to your left.

The person who gets the coin then repeats the process, flipping it and passing it to their right or left based on the result. This cycle continues until there is only one person left who has not yet received the coin.

This last remaining individual, who has not touched the coin, is announced as the winner and is given the responsibility to host the next dinner party.

Note, because you were the first to flip the coin in the game, you are immediately disqualified from the possibility of hosting the upcoming dinner party.