In [2]:
%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
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.
In [6]:
d6 = Pmf(range(1,7))
d6.Print()
In [8]:
twice = d6 + d6
twice.Print()
In [10]:
twice[2] = 0
twice[3] = 0
twice[4] = 0
twice.Normalize()
twice.Print()
In [13]:
remaining = twice - 4
remaining.Print()
In [16]:
d6.ProbGreater(remaining) + d6.ProbEqual(remaining)
Out[16]: