# Python!

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

Click here to link back to the main page.

Probability Puzzles

If you know of any fun probability puzzles, please get in touch with me! I am constantly trying to find new puzzles to add.

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

Birthday Paradox

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?

Click here to view my solution.

Simulating A Multiple-Choice Exam

Everyone can relate to taking an exam and finding yourself guessing at the answers more than 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.

Click here to view my solution.

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?

Click here to view my solution.

How Many People Are Visible?

There are five 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 five people are possible that would have exactly three people visible to you?

Click here to view my solution.

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 randomly choose another seat.

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

Click here to view my solution.

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 equals 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?

Click here to view my solution.

Loaded Coin Riddle

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 ensure a fair contest 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.

Click here to view my solution.

How Many Visitors?

If my super fancy puzzle website averages twelve visitors daily, what are the chances of…..

Getting exactly ten visitors a day?

Getting ten or more visitors a day?

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

Click here to view my solution.

Unknown Deck of Cards

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

Click here to view my solution.

Unfair Dice

You have two dice; one is fair, and the other is unfair. The unfair dice rolls a six 50% of the time.

What is the probability of choosing the unfair dice if you randomly select a dice and roll a six?

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.

Click here to view my solution.

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 two straight games of checkers. But you must play at least one game against the warden and one game against the sheriff. You know the sheriff plays a better game of checkers than 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 than the warden, and you must win two straight games.

Click here to view my solution.

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 two-day stay in purgatory, and one door leads to a three-day stay in purgatory. Once you complete 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?

Click here to view my solution.

Favorite Child

You live in a society where female children are preferred over male children. By law, couples must conceive children until they produce a female offspring. If their first child is male, they can 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?

Click here to view my solution.

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, a 2/5 chance of being idle, and a 1/5 chance of replicating. After replication, each cell has the same probability of either dying, being idle, or replicating.

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

Click here to view my solution.

Shuffled Card Deck

Given a randomly shuffled deck of cards, where the numbered cards are equal to their face value, the Ace is equal to one, a Jack is equal to eleven, a Queen is equal to twelve, and a King is equal to thirteen.

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 deck’s 1st, 14th, 27th, or 40th place, it would be considered in its proper numerical place.

Click here to view my solution.

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 one through six. 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 one hundred times and keep the sum of your bankroll at the end of the one hundred dice rolls.

What are the odds of winning?

Click here to view my solution.

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?

Click here to view my solution.

Estimation Of The Mean

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

1. Based on 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 five hundered times, and record the win percentage. What are your highest and lowest win percentages? What is the win percentage at the 99% and 1% percentiles?

Click here to view my solution.

Coupon Collecting

This problem is called the coupon collector’s problem.

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

Click here to view my solution.

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?

Click here to view my solution.

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 throwing a complete game?

Click here to view my solution.

Simulating a Basketball Game

Utilizing the average NBA shooting statistics from the 2022-2023 season, the three-point shooting success rate is 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 attempts. Each team is given exactly ninety shot attempts in each game. Conduct a comprehensive statistical evaluation of the ensuing results.

Click here to view my solution.

Simulating the Monty Hall Problem

Run a simulation of the Monty Hall problem.

Click here to view my solution.

Winning Percentage

Your favorite football team has the following pre-season estimated win percentages for their twelve-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% for each of the twelve games.

Click here to view my solution.

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 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?

Click here to view my solution.

Keep the Prize

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

After the meal, all attendees, including yourself, gather around a circular table. As the current host, you 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 yet to receive 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 that 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.

Click here to view my solution.

Sicherman Dice

Sicherman dice are a pair of six-sided dice with non-standard numbers–one with the sides 1, 2, 2, 3, 3, and 4, and the other with the sides 1, 3, 4, 5, 6, and 8. They are notable as the only pair of six-sided dice that bear only positive integers and have the same probability distribution for the sum as normal dice.

Run a simulation to prove Sicherman dice have the same probability as a normal pair of dice.

Click here to view my solution.

Happy coding!