Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96144
License: OTHER
Kernel: Python 3

The goblin problem

Allen Downey

MIT License

%matplotlib inline import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns sns.set(style='white') from thinkstats2 import Pmf, Cdf import thinkstats2 import thinkplot decorate = thinkplot.config

The goblin problem

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 4 points of damage. What is your probability of defeating the goblin with your next successful attack?

(Where "defeat" means that the goblin can withstand no more damage.)

Note: You can solve this problem with paper and pencil or computationally; you can solve it using Bayes's Theorem, combinatorics, or using the Pmf class.

d6 = Pmf(range(1,7)) d6.Print()
1 0.16666666666666666 2 0.16666666666666666 3 0.16666666666666666 4 0.16666666666666666 5 0.16666666666666666 6 0.16666666666666666
twice = d6 + d6 twice.Print()
2 0.027777777777777776 3 0.05555555555555555 4 0.08333333333333333 5 0.1111111111111111 6 0.1388888888888889 7 0.16666666666666669 8 0.1388888888888889 9 0.1111111111111111 10 0.08333333333333333 11 0.05555555555555555 12 0.027777777777777776
twice[2] = 0 twice[3] = 0 twice[4] = 0 twice.Normalize() twice.Print()
2 0.0 3 0.0 4 0.0 5 0.1333333333333333 6 0.16666666666666663 7 0.19999999999999998 8 0.16666666666666663 9 0.1333333333333333 10 0.09999999999999998 11 0.06666666666666665 12 0.033333333333333326
remaining = twice - 4 remaining.Print()
-2 0.0 -1 0.0 0 0.0 1 0.1333333333333333 2 0.16666666666666663 3 0.19999999999999998 4 0.16666666666666663 5 0.1333333333333333 6 0.09999999999999998 7 0.06666666666666665 8 0.033333333333333326
d6.ProbGreater(remaining) + d6.ProbEqual(remaining)
0.5499999999999998