Created
December 6, 2018 15:31
-
-
Save juanmacuevas/e906d74c4f8cb54720ffaef3757568fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def map_sums_to_throws(dice,sides): | |
x = list(range(1,sides+1)) | |
d = {} | |
l = [p for p in itertools.product(x, repeat=dice)] | |
for i in l: | |
s = sum(i) | |
if s not in d: | |
d[s]=1 | |
else: | |
d[s]+=1 | |
return d | |
sums9d4 = map_sums_to_throws(9,4) | |
sums6d6 = map_sums_to_throws(6,6) | |
## accum throws that sum up to i | |
accum6d6 = {6:1} | |
for i in range(6+1,(6*6)+1): | |
accum6d6[i]=sums6d6[i]+accum6d6[i-1] | |
## prob sum 9d4 equals i times sum 6d6 less than i | |
suma = 0 | |
for i in range(9,9*4+1): | |
p9d4is_i,p6d6less_i = (sums9d4[i]/4**9),(accum6d6[i-1]/6**6) | |
suma+= p9d4is_i*p6d6less_i | |
print(round(suma,7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment