4
$\begingroup$

I'm trying to figure out how to get the probability that you reach a certain point in my game.

The way it works is that you start off with 22 things (including yourself), and each time you press enter a random thing explodes and you get a point.

The twist is that if something explodes, that thing cannot be exploded again. So now there are 21 options.

If you explode yourself, the game obviously ends. Here's my simplified code:

#Dynamite simulator import random, time killOptions = ["Yourself","A Bush","Rodeen","A Tree","Your Laptop","Your Water","Your Friend","John Paul","Your Teacher","A Rastin","Peter Yao","The Earth","The ISS","Armagedon","Thor","Jacob's IPad","The Bomb","A Random Short Person Who's Name Is Coincidentally Jehan","Grass","The Imposter","Bob The Builder","Math Equations"] killLength = len(killOptions) points = 0 def GameOver(): time.sleep(3) print("\nYou blew yourself up, so you died. Duh.") if points != killLength: print(f'\nYou got {points} points.') else: print(f'\nYou got the maximum score of {killLength}. Lucky...') quit() def BlowUp(): print(random.choice(boomOptions)) thingToBlowUp = random.choice(killOptions) killOptions.remove(thing) print(f'\nYou killed {thing}.') if thing == "Yourself": GameOver() print('Press Enter To Blow Dynamite') while True: input() BlowUp() points += 1 print(f'There are {len(killOptions)} more things to blow up.') 

I'm kinda bad at math, so how would you get the probability of someone getting n points?

I asked at stack overflow, but they redirected me here

$\endgroup$
3
  • $\begingroup$ related: stats.stackexchange.com/questions/354552/… $\endgroup$ Commented May 19, 2023 at 15:55
  • $\begingroup$ NameError: name 'boomOptions' is not defined. Did you mean: 'killOptions'? there is zero probability to reach any points. $\endgroup$ Commented May 19, 2023 at 16:42
  • $\begingroup$ Also, if you would blow up the earth, then you die as well. In addition, if you blow up the math equations then the probability does not exist. $\endgroup$ Commented May 19, 2023 at 16:48

3 Answers 3

6
$\begingroup$

This is described by the negative hypergeometric distribution, but you can also derive this by hand. Example:

  • The probability you explode on turn 1 is $P(t_1)= 1/22$. This gives you 0 points.
  • To explode on $t_2$, you have to first not explode at $t_1$. The probability of that is $P(!t_1)=21/22$ (the ! sign means "not"). The probability you explode on turn 2, is $P(t_2) = P(t_2 | !t_1)P(!t_1)$, which is the probability you explode on turn 2 given (the | sign) you didn't explode on turn 1, multiplied by the probability you didn't explode at turn 1. Overall, this is $P(t_2) = P(t_2 | !t_1)P(!t_1) = \frac{1}{21}\frac{21}{22}=1/22$. This gives you 1 point.
  • The equations get a bit longer at this stage (exploding on $t_3$, $t_4$ etc.), but basically - the probability that you explode on any stage is 1/22 - or $1/N$ assuming that there is only one failure case (exploding yourself) out of $N$ things to explode.

Overall, the probability of getting $x$ points (where $x$ ranges from the minimum, 0 points, to the maximum, 21 points), is always $1/22 = 0.0454545\cdots$.

$\endgroup$
5
$\begingroup$

Let $k$ be the number of points You collect. To collect exactly $k$ points You must survive $k$ steps and explode in $k+1$ step, so it's a sequence of events: NN...ND where N is 'not dead', D means 'dead' and 'N' is present $k$ times in the sequence. At each step the probability of 'N' gets smaller as the number of items decreases. The events are independent, I assume. At first step there's $\frac{21}{22}$ chances to get N and $\frac{1}{21}$ to get D. At the second step, there's $\frac{21}{22} \cdot \frac{20}{21}$ chances of getting NN sequence and $\frac{1}{20}$ to get D, and so on. At $k$-th step You get $\frac{21}{22} \cdot \frac{20}{21} \cdot \dots \cdot \frac{22 - k}{22 - k + 1} \cdot \frac{1}{22 - k}$. As You may notice the neighbor terms will cancel their nominators and denominators. Finally, You'll get the formula $\frac{22 - k}{22} \cdot \frac{1}{22 - k} = \frac{1}{22}$. So in general, the probability of getting k points is $\frac{n - k}{n} \cdot \frac{1}{n - k} = \frac{1}{n}$, where n is the number of items at the beginning. The probability is constantly equal $\frac{1}{22}$. $k$ seen as a random variable is uniformly distributed on discrete scale 0, 1, ..., 22.

$\endgroup$
1
  • $\begingroup$ Oh nice. I like this explanation. $\endgroup$ Commented May 19, 2023 at 10:04
3
$\begingroup$

Suppose that we don't stop the game when you blow up; we just stop accumulating points. This will not change the probability of getting a certain number of points, and it makes it easier to analyze.

All games now take exactly 22 turns, and can be described by an ordering of the things that get blown up. There are 22! such orderings, all equally probable. There are 21! orderings in which you blow up on the last turn. So the probability that you get one of those orderings is 21!/22! = 1/22.

Even more simply, we don't need to work out all the combinations. We can select the elements in whatever order we want, so long as we aren't permitted to choose something we already blew up, so let's start with the last one instead of the first. Since we haven't eliminated any possibilities yet, there are 22 options (selected from uniformly), and thus a 1/22 chance that that'll be the turn where you blow up.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.