AllenDowney / BayesMadeSimple

Code for a tutorial on Bayesian Statistics by Allen Downey.
340 stars 210 forks source link

Incorrect solution: Dungeons & Dragons Bonus #10

Closed rsokl closed 4 years ago

rsokl commented 4 years ago

First of all, thank you for putting on a great tutorial!

I believe I found bad solution in the cookie-notebook.

Bonus exercise: In Dungeons and Dragons, the amount of damage a goblin can withstand is the sum of two six-sided dice. The amount of damage you inflict with a short sword is determined by rolling one six-sided die.

Suppose you are fighting a goblin and you have already inflicted 3 points of damage. What is your probability of defeating the goblin with your next successful attack?

The provided solution is:

d6 = Pmf()
for x in [1,2,3,4,5,6]:
    d6[x] = 1
d6.normalize()

twice = d6.add_dist(d6)
twice[2] = 0
twice[3] = 0
twice.normalize()

>>> d6.ge_dist(twice)
0.11111111111111109

This implies that Goblin's health should be reduced, due to the 3 damage you already did, by creating the posterior over the Goblin's health with the assumption that it does not have 1-3 health remaining. Clearly this is not correct. The blow means that the Goblin's health must lie in the interval [1, 9], not [4, 12]

The correct solution, I believe, would be:

d6 = Pmf()
for x in [1,2,3,4,5,6]:
    d6[x] = 1
d6.normalize()

twice = d6.add_dist(d6)
goblin_health = twice.copy()

# 3 HP of damage already dealt:
dmg3 = Pmf()
dmg3[3] = 1.
sword = d6.copy().add_dist(dmg3)

>>> sword.ge_dist(goblin_health)
0.5
AllenDowney commented 4 years ago

You are correct. I have updated this notebook with a correct solution. Thank you!