## What Is the St. Petersburg Paradox?

- Ph.D., Mathematics, Purdue University
- M.S., Mathematics, Purdue University
- B.A., Mathematics, Physics, and Chemistry, Anderson University

You’re on the streets of St. Petersburg, Russia, and an old man proposes the following game. He flips a coin (and will borrow one of yours if you don’t trust that his is a fair one). If it lands tails up then you lose and the game is over. If the coin lands heads up then you win one ruble and the game continues. The coin is tossed again. If it is tails, then the game ends. If it is heads, then you win an additional two rubles. The game continues in this fashion. For each successive head we double our winnings from the previous round, but at the sign of the first tail, the game is done.

How much would you pay to play this game? When we consider the expected value of this game, you should jump at the chance, no matter what the cost is to play. However, from the description above, you probably wouldn’t be willing to pay much. After all, there is a 50% probability of winning nothing. This is what is known as the St. Petersburg Paradox, named due to the 1738 publication of Daniel Bernoulli *Commentaries of the Imperial Academy of Science of Saint Petersburg*.

### Some Probabilities

Let’s begin by calculating probabilities associated with this game. The probability that a fair coin lands heads up is 1/2. Each coin toss is an independent event and so we multiply probabilities possibly with the use of a tree diagram.

- The probability of two heads in a row is (1/2)) x (1/2) = 1/4.
- The probability of three heads in a row is (1/2) x (1/2) x (1/2) = 1/8.
- To express the probability of
*n*heads in a row, where*n*is a positive whole number we use exponents to write 1/2*n*.

### Some Payouts

Now let’s move on and see if we can generalize what the winnings would be in each round.

- If you have a head in the first round you win one ruble for that round.
- If there is a head in the second round you win two rubles in that round.
- If there is a head in the third round, then you win four rubles in that round.
- If you have been lucky enough to make it all the way to the
*n*th round, then you will win 2*n-1*rubles in that round.

### Expected Value of the Game

The expected value of a game tells us what the winnings would average out to be if you played the game many, many times. To calculate the expected value, we multiply the value of the winnings from each round with the probability of getting to this round, and then add all of these products together.

- From the first round, you have probability 1/2 and winnings of 1 ruble: 1/2 x 1 = 1/2
- From the second round, you have probability 1/4 and winnings of 2 rubles: 1/4 x 2 = 1/2
- From the first round, you have probability 1/8 and winnings of 4 rubles: 1/8 x 4 = 1/2
- From the first round, you have probability 1/16 and winnings of 8 rubles: 1/16 x 8 = 1/2
- From the first round, you have probability 1/2
*n*and winnings of 2*n-1*rubles: 1/2*n*x 2*n-1*= 1/2

The value from each round is 1/2, and adding the results from the first *n* rounds together gives us an expected value of *n*/2 rubles. Since *n* can be any positive whole number, the expected value is limitless.

### The Paradox

So what should you pay to play? A ruble, a thousand rubles or even a billion rubles would all, in the long run, be less than the expected value. Despite the above calculation promising untold riches, we would all still be reluctant to pay very much to play.

There are numerous ways to resolve the paradox. One of the simpler ways is that no one would offer a game such as the one described above. No one has the infinite resources that it would take to pay someone who continued to flip heads.

Another way to resolve the paradox involves pointing out how improbable it is to get something like 20 heads in a row. The odds of this happening are better than winning most state lotteries. People routinely play such lotteries for five dollars or less. So the price to play the St. Petersburg game should probably not exceed a few dollars.

If the man in St. Petersburg says that it will cost anything more than a few rubles to play his game, you should politely refuse and walk away. Rubles aren’t worth much anyway.

Learn about the St. Petersburg paradox and why relying upon the expected value in this situation leads to a conclusion no rational person would make.

## St petersburg lottery

GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

#### GitHub is where the world builds software

Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

##### Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

##### Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

##### Launching Xcode

If nothing happens, download Xcode and try again.

##### Launching Visual Studio

### Latest commit

### Git stats

### Files

Failed to load latest commit information.

### README.md

The St. Petersburg paradox or St. Petersburg lottery is a paradox related to probability and decision theory in economics.

It is based on a particular (theoretical) lottery game that leads to a random variable with infinite expected value (i.e., infinite expected payoff)

but nevertheless seems to be worth only a very small amount to the participants.

The St. Petersburg paradox is a situation where a naive decision criterion which takes only the expected value into account predicts a course of action that presumably no actual person would be willing to take.

Several resolutions are possible.

### About

Python CLI implementation of the St. Petersburg Paradox / St. Petersburg lottery

Python CLI implementation of the St. Petersburg Paradox / St. Petersburg lottery – danthelion/python-st-petersburg-paradox