-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmatrix-205.py
35 lines (28 loc) · 964 Bytes
/
matrix-205.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
score_hash = {}
score_hash_2 = {}
total_rolls = 4**9
total_rolls_2 = 6**6
import itertools
def score(x, scores):
sum_x = sum(x)
if not scores.has_key(sum_x):
scores[sum_x] = 0
scores[sum_x] += 1
r = lambda: range(1,5)
map(lambda x: score(x, score_hash),itertools.product(r(),r(),r(),r(),r(),r(),r(),r(),r()))
r = lambda: range(1, 7)
map(lambda x: score(x, score_hash_2), itertools.product(r(),r(),r(),r(),r(),r()))
scores_matrix = []
probabilities_matrix = []
for x in itertools.product(score_hash, score_hash_2):
key1 = x[0]
key2 = x[1]
if key1 > key2:
scores_matrix.append(1)
else:
scores_matrix.append(0)
for key1 in score_hash:
for key2 in score_hash_2:
probability = score_hash[key1]/float(total_rolls) * score_hash_2[key2]/float(total_rolls_2)
probabilities_matrix.append(probability)
print sum(map((lambda x: x[0]*x[1]), zip(scores_matrix, probabilities_matrix)))