Probability of A Winning a Duel with One Gun and One Bullet

In summary, A and B decide to duel with one gun and one bullet. They take turns shooting at each other until one is killed. The probability of A winning is 0.50 if the cylinder is spun before each shot and 0.54 if it is not spun.
  • #1
Arman777
Insights Author
Gold Member
2,168
192
Problem:

A and B decide to duel but, being poor, they have just one gun (a six-shot revolver) and only one bullet. Being dumb, as well, this does not deter them and they agree to "duel" as follows: They will insert the lone bullet into the gun's cylinder, A will then spin the cylinder and shoot at B (who, standing inches away, is impossible to miss). If the gun doesn't fire then A will give the gun to B, who will spin the cylinder and then shoot at A. This back-and-forth duel will continue until one fool shoots the other. What is the probability that A will win?

Python:
import random

a_wins = 0
for i in range(10**6):
    Chances = ["d","nd","nd","nd","nd","nd"]  #nd = not dead, d = dead
    while len(Chances)> 0:
        b = random.choice (Chances)  #A shoots B
        if b == "d":
            a_wins += 1
            break
        else:
            Chances.remove("nd")
            a = random.choice(Chances)  #B shoots A
            if a == "d":
                break  #A cannot win
            else:
                Chances.remove("nd")   #wasting antoher chance
print(a_wins/10**6)

I am getting 0.50 however the correct answer is 0.54 so I guess I am missing something abour related to the first shoot ? Anyone can help. Thanks
 
Technology news on Phys.org
  • #2
You don't have to remove the nd, because B spin the cylinder again before shooting.
 
  • Like
Likes zivo and Arman777
  • #3
As @Gaussian97 says, you shoudn't remove the "nd" from Chances; the Chances are the same for each shot.

Gaussian97 said:
because B spin the cylinder again before shooting.

That makes a random choice among the chances correct for each shot, but it doesn't explain why the chances are the same for each shot. The reason the chances are the same for each shot is that the number of slots is the same (6) for all shots--an empty slot doesn't get removed if a shot is attempted but nothing fires.
 
  • #4
PeterDonis said:
you shoudn't remove the "nd" from Chances

This also means your inner while loop does not need the len(Chances) > 0 condition; that will always be true since you're not removing elements from Chances. It can just be while True (the two break statements are the only way to exit the loop).
 
  • Like
Likes Arman777
  • #5
PeterDonis said:
As @Gaussian97 says, you shoudn't remove the "nd" from Chances; the Chances are the same for each shot.
That makes a random choice among the chances correct for each shot, but it doesn't explain why the chances are the same for each shot. The reason the chances are the same for each shot is that the number of slots is the same (6) for all shots--an empty slot doesn't get removed if a shot is attempted but nothing fires.
It really does, in fact, the code that @Arman777 has written is exactly the one you should use to simulate the case without B spinning before (and has a probability of 50%). The reason is that if you don't spin every round, once you spin, the bullet is in a concrete spot and you will kill the other in 6 or fewer tries, so once you have "shoot" an empty spot you will never shoot it again.
 
  • Like
Likes arivero and Arman777
  • #6
Arman777 said:
I am getting 0.50

As a useful exercise, you might want to prove that 0.50 is in fact what you should get if you do remove an "nd" from Chances each time a shot is attempted but not fired--or, to put it another way, if the gun was a special gun that ejected an empty slot (reducing the total number of slots by 1) if a shot was attempted but not fired.
 
  • Like
Likes Arman777
  • #7
I sure hope this is a paintball gun but didn’t if kenos of any made with a 6 shot cylinder.

I suppose for a paintball gun you could put 5 white balls and one red ball in the hopper and shake it up before shooting although I think after a shot the gun loads another ball.

The notion of dropping a shot each round sounds almost like the Josephus puzzle where you and many others make a circle and you cycle around the circle eliminating the player next to you until only is left.
 
  • Like
Likes Arman777
  • #8
jedishrfu said:
Josephus puzzle

I know that game..See it on numberphile. Maybe at some other time, I can write a code for that. I think it would not be so hard
PeterDonis said:
As a useful exercise, you might want to prove that 0.50 is in fact what you should get if you do remove an "nd" from Chances each time a shot is attempted but not fired--or, to put it another way, if the gun was a special gun that ejected an empty slot (reducing the total number of slots by 1) if a shot was attempted but not fired.

Like mathematically? My probability theory is not so great...

For spinning the cylinder case, I would have expected P= 0.50 since it seems more random. However, without spinning the cylinder, the first shooter always has more chance (or it seems to me that way ) so it's somewhat interesting to see such results.
While I was reading the question I did not pay attention to the spinning case.. thanks then

PeterDonis said:
This also means your inner while loop does not need the lens(Chances) > 0 conditions; that will always be true since you're not removing elements from Chances. It can just be while True (the two break statements are the only way to exit the loop).

Yes, you are right.
 
  • #9
Arman777 said:
For spinning the cylinder case, I would have expected P= 0.50 since it seems more random. However, without spinning the cylinder, the first shooter always has more chance (or it seems to me that way )

You have these backwards.

If you don't spin the cylinder after each firing attempt, then both shooters must have an equal chance at winning, i.e., P = 0.50, since the first shooter wins if the bullet is in an odd-numbered slot (numbering the slots 1 through 6 in the order they will be in the firing position) and the second shooter wins if the bullet is in an even-numbered slot, and there are the same number of both kinds of slots, so there is an equal chance of the bullet being in an odd or even slot.

If you spin the cylinder after each firing attempt, and the number of slots is fixed at 6 (as in any real gun), then the probability that the first shooter wins is 6/11 or 0.54 (which is what I assumed you were referring to when you said the correct answer is 0.54). But even without doing the calculation, it can be seen intuitively that the first shooter has an advantage in this scenario, simply because he shoots first. What the randomization of the cylinder by spinning does is make the chance of the bullet being in the firing position the same on each spin (a 1/6 chance); but that's not the same as making both shooters have the same chance of winning; if everything else about the scenario is the same between both shooters, then the one difference between them that you can't eliminate--that one of them shoots first--will be the deciding factor.

The interesting thing is that, if you do spin the cylinder after each attempt, but once a particular slot is used it can't be used again (either it's ejected from the gun or otherwise made unusable, so the cylinder will skip it on future spins), then you also have P = 0.50, not 0.54--i.e., both shooters have an equal chance at winning.
 
  • Like
Likes Arman777
  • #10
PeterDonis said:
If you don't spin the cylinder after each firing attempt, then both shooters must have an equal chance at winning, i.e., P = 0.50, since the first shooter wins if the bullet is in an odd-numbered slot (numbering the slots 1 through 6 in the order they will be in the firing position) and the second shooter wins if the bullet is in an even-numbered slot, and there are the same number of both kinds of slots, so there is an equal chance of the bullet being in an odd or even slot.
Oh I understand it now.
PeterDonis said:
The interesting thing is that, if you do spin the cylinder after each attempt, but once a particular slot is used it can't be used again (either it's ejected from the gun or otherwise made unusable, so the cylinder will skip it on future spins), then you also have P = 0.50, not 0.54--i.e., both shooters have an equal chance at winning.
It s interesting. I think my initial code was referring to spinning case but cannot using the same slot ?
 
  • #11
Arman777 said:
I think my initial code was referring to spinning case but cannot using the same slot ?

Yes, your initial code was removing a slot every time a firing attempt was made but no bullet was in the slot, and then spinning the cylinder (since you were randomly choosing among the remaining slots each time).
 
  • Like
Likes Arman777
  • #13
Actually the question has another part which is like this

Now, here's your problem. Our two idiots have decided, after reading the preceding analysis, to use a different procedure. They still have just one gun and one bullet but now, with each exchange of the gun, they get one additional trigger pulL

That is, A puts the bullet in the cylinder, spins it and then shoots at B. If the gun doesn't fire, A gives the gun to B, who spins the cylinder and then shoots at A. If the gun doesn't fire, B spins the cylinder again and gets a second try. If the gun still doesn't fire, B gives the gun to A, who gets a maximum of three trigger pulls (with a spin of the cylinder between pulls), and so on.

Calculate P(A) theoretically.

This has also interesting result. I tried to write a code and this is the my code and P(A) this time becomes 0.52..

Python:
import random

chances = ["d", "nd", "nd", "nd", "nd", "nd"]def a_shoots(chances, trigger_num):
    for i in range(trigger_num):
        b = random.choice(chances)
        if b == "d":
            return Truedef b_shoots(chances, trigger_num):
    for i in range(trigger_num):
        a = random.choice(chances)
        if a == "d":
            return True

a_wins = 0
for i in range(10**6):
    trigger_num = 1
    while True:
        A = a_shoots(chances, trigger_num)
        if A == True:
            a_wins += 1
            break
        else:
            trigger_num += 1
            B = b_shoots(chances, trigger_num)
            if B == True:
                break
            else:
                trigger_num += 1

print(a_wins/10**6)

It seems that shooting first is important in any case
 
  • #14
Arman777 said:
Actually the question has another part which is like this

What is this question from? Is it a homework problem?
 
  • #15
PeterDonis said:
What is this question from? Is it a homework problem?
Oh no, it's not homework. I am just studying the Monte Carlo algorithm. My professor recommended me some books which are related to Monte Carlo and this problem is in the book.

https://press.princeton.edu/titles/6914.html
 
  • #16
One comment I have about your code is that there should be comments in it. The fact that the number of trigger pulls increases each time they exchange the gun should be indicated in a comment. Other comments explaining things would also be nice. Inputs and outputs of functions should be defined in comments.

PS. If large programs are in your future (don't underestimate that possibility), it would be good to get used to writing comments in a format that Doxygen (or Sphinx?) can understand.
 
Last edited:
  • Like
Likes sysprog and Arman777
  • #17
I ll be more careful on that idea. I ll put comments from now to get used to it..Thanks also for the formatting ideas.
 
  • Like
Likes FactChecker and sysprog
  • #18
Note that the analytical consideration for the original case is much simpler than writing the code. All you need is some very basic considerations:
- What is the probability for the fool that is to shoot to win in the current shot?
- What is the probability that the fool misses?
- Given that the fool misses, what is the probability of him winning?
The total probability of winning is the sum of the probabilities of winning immediately and that of missing and winning anyway.
 
  • Like
Likes sysprog and Arman777
  • #19
Another programming comment. Although Python has a default function return value of None, I think that is unusual among programming languages. I recommend that you get in the habit of specifying a function return value in all cases:

Specify return value in all cases:
def b_shoots(chances, trigger_num):
    for i in range(trigger_num):
        a = random.choice(chances)
        if a == "d":
            return True
    return False
 
  • Like
Likes Klystron
  • #20
FactChecker said:
Another programming comment. Although Python has a default function return value of None, I think that is unusual among programming languages. I recommend that you get in the habit of specifying a function return value in all cases:

Specify return value in all cases:
def b_shoots(chances, trigger_num):
    for i in range(trigger_num):
        a = random.choice(chances)
        if a == "d":
            return True
    return False

Return False for in any case ?
 
  • #21
Orodruin said:
Note that the analytical consideration for the original case is much simpler than writing the code. All you need is some very basic considerations:
- What is the probability for the fool that is to shoot to win in the current shot?
- What is the probability that the fool misses?
- Given that the fool misses, what is the probability of him winning?
The total probability of winning is the sum of the probabilities of winning immediately and that of missing and winning anyway.
Well its simpler indeed but that's not so much fun :)
 
  • #22
Arman777 said:
Return False for in any case ?
Return False if it made it through the entire "for i" loop and didn't return True. That is when it was returning None.
 
  • #23
FactChecker said:
One comment I have about your code is that there should be comments in it.

Also: You've got a duplicate function: one for A and an identical one for B. That's not good coding for several reasons. A good exercise would be to rewrite it as a single function for both shooters.
 
  • #24
DaveC426913 said:
Also: You've got a duplicate function: one for A and an identical one for B. That's not good coding for several reasons. A good exercise would be to rewrite it as a single function for both shooters.
I see thanks for your comment. And I change my code by just using one function
 
  • #25
FactChecker said:
Return False if it made it through the entire "for i" loop and didn't return True. That is when it was returning None.
Yes I unerstand it thanks then.
 
  • #26
Just an empirical fact to throw into the mix: when the cylinder of the 6-shot revolver is spun, with one slot loaded and the others empty, if the pistol and cylinder are closer to upright than to upside-down when the cylinder is spun, there is a gravitational bias against the cartridge being in battery when the cylinder is repositioned into the frame after the spin.
 
  • Like
Likes Arman777
  • #27
FactChecker said:
Another programming comment. Although Python has a default function return value of None, I think that is unusual among programming languages. I recommend that you get in the habit of specifying a function return value in all cases:

Specify return value in all cases:
def b_shoots(chances, trigger_num):
    for i in range(trigger_num):
        a = random.choice(chances)
        if a == "d":
            return True
    return False
Please note also that Python retains, as distinguished from discarding, the value of the variable used for incrementation in a FOR (lowercase in Python) loop -- the value of that variable remains interrogable, and at the number of times the code inside the loop has run, after the loop is concluded -- in BASIC that value is zero after the loop . . .
 
  • #28
No doubt fools might duel using a single revolver. True idiots would use a semi-automatic pistol.
 

1. What is the probability of A winning a duel with one gun and one bullet?

The probability of A winning a duel with one gun and one bullet depends on several factors such as the distance between the two dueling parties, their shooting accuracy, and the speed at which they pull the trigger. However, assuming all other factors are equal, the probability of A winning would be 50%, as there are only two possible outcomes - A wins or A loses.

2. Does the type of gun affect the probability of A winning the duel?

Yes, the type of gun can affect the probability of A winning the duel. For example, if A is using a more modern and accurate gun compared to B's old and rusty gun, A may have a higher chance of winning. Additionally, factors such as the weight and recoil of the gun can also impact the probability of A winning.

3. How does the distance between the two parties affect the probability of A winning?

The distance between the two parties can greatly affect the probability of A winning the duel. Generally, the closer the distance, the higher the chances of A winning, as it allows for more accuracy when shooting. However, if the distance is too close, it can also give an advantage to B, as they may be able to grab the gun before A can shoot.

4. Can the probability of A winning be calculated mathematically?

Yes, the probability of A winning can be calculated mathematically using the principles of probability and statistics. However, it would require accurate data on factors such as shooting accuracy and reaction time, which may vary from person to person. Therefore, the calculated probability may not always accurately reflect the actual outcome of the duel.

5. Are there any other variables that can affect the probability of A winning the duel?

Yes, there are many other variables that can affect the probability of A winning the duel. Some examples include the physical and mental state of the two parties, their experience with guns, and any external factors such as weather conditions or distractions. These variables can greatly impact the outcome of the duel and should be taken into consideration when calculating the probability of A winning.

Similar threads

  • Programming and Computer Science
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
14
Views
2K
  • Precalculus Mathematics Homework Help
Replies
12
Views
2K
Replies
4
Views
2K
  • Special and General Relativity
2
Replies
56
Views
8K
  • Calculus and Beyond Homework Help
Replies
1
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
2K
Replies
20
Views
4K
Replies
7
Views
21K
  • Precalculus Mathematics Homework Help
Replies
18
Views
3K
Back
Top