AllenDowney / ThinkBayes2

Text and code for the forthcoming second edition of Think Bayes, by Allen Downey.
http://allendowney.github.io/ThinkBayes2/
MIT License
1.8k stars 1.49k forks source link

Chapter 6 Goblin Exercise #51

Closed cjungerius closed 2 years ago

cjungerius commented 2 years ago

Hi,

I'm working through the book atm, and I think I spotted a slight inaccuracy in the phrasing of the Goblin HP problem in Chapter 6 (Odds & Addends):

The phrasing of the question is 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 solution subtracts a 1d6+3 distribution from a 2d6 distribution and looks at the likelihood of the remainder being < 0, which returns 0.5. However, given the phrasing you have already inflicted 3 points of damage and what is probability of defeating the goblin with your *next* successful attack?, am I right in assuming that the initial hit point distribution is necessarily greater than 3 (since the goblin is apparently still standing)?

Assuming I'm correct, would the hp distribution be more accurately described by

hp = make_die(6).add_dist(make_die(6))
hypos = hp.qs
impossible = hypos <= 3
hp.ps[impossible] = 0
hp.normalize()

Alternatively, phrased as likelihood over the whole array of hypos:

#prior hp
hp = make_die(6).add_dist(make_die(6))
hypos = hp.qs
#likelihood of the goblin standing after 3 dmg:
likelihood = [hypo > 3 for hypo in hypos]
#updating prior given data:
hp *= likelihood
hp.normalize()

This lead me to the following solution

damage = make_die(6).add_dist(3)
remainder = hp.sub_dist(damage)
remainder.le_dist(0)

which returns 0.45454545 (as opposed to 0.5 in the original phrasing of the solution)

Please let me know if I'm barking up the wrong tree here! It's possible I overthought things, but figured I'd post this here.

AllenDowney commented 2 years ago

Hi Chris, On a quick read, I think you are right. In fact, I think I had a correct solution in a previous version and then broke it at some point. I will review this and push a correction when I have a chance. Thank you!

AllenDowney commented 2 years ago

I have made this fix, just need to propagate the change. Thank you!