Problem 205

completed February 4, 2012

Comments

I’m not very good with probability. I’ve never taken a stats class. So, before going into this one, I wanted to make sure I really understood what I was looking for.

I did a bunch of reading on Wikipedia and Wolfram MathWorld about probability and realized I needed the Total Probability Theorem. P(B) = P(B|A1)P(A1) + …

Results

With this knowledge, the script ran correctly the first time!

Code

from itertools import *

PeterDict = dict(zip(range(37), [0]*37))
ColinDict = dict(zip(range(37), [0]*37))
for game in product(range(1,5), range(1,5), range(1,5), range(1,5), range(1,5), range(1,5), range(1,5), range(1,5), range(1,5)):
	PeterDict[sum(game)] += 1

for game in product(range(1,7), range(1,7), range(1,7), range(1,7), range(1,7), range(1,7)):
	ColinDict[sum(game)] += 1

PeterSum = 0
ColinSum = 0

for Ps in PeterDict.itervalues():
	PeterSum += Ps
for Cs in ColinDict.itervalues():
	ColinSum += Cs

P = 0
for Colin in ColinDict.iterkeys():
	PeterWins = 0
	ColinProb = (ColinDict[Colin]/float(ColinSum))
	for Peter in PeterDict.iterkeys():
		if Peter > Colin:
			PeterWins += PeterDict[Peter]
	P += ColinProb * (PeterWins/float(PeterSum))

print P