Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 6 Goblin Exercise #51

Closed
cjungerius opened this issue Oct 31, 2021 · 2 comments
Closed

Chapter 6 Goblin Exercise #51

cjungerius opened this issue Oct 31, 2021 · 2 comments

Comments

@cjungerius
Copy link

cjungerius commented Oct 31, 2021

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
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants