euler/python/e205.py

36 lines
953 B
Python

from lib_misc import get_item_counts
def acc(scores, faces, rem):
if rem == 0:
return scores
nscores = []
for f in faces:
for s in scores:
nscores.append(f + s)
return acc(nscores, faces, rem - 1)
def euler_205():
scores_four = acc([0], [1, 2, 3, 4], 9)
scores_six = acc([0], [1, 2, 3, 4, 5, 6], 6)
all_combinations = len(scores_four) * len(scores_six)
four_won_count = 0
for four_value, four_count in get_item_counts(scores_four).items():
current_six_count = 0
for six_value, six_count in get_item_counts(scores_six).items():
if four_value > six_value:
current_six_count += six_count
four_won_count += (four_count * current_six_count)
p = four_won_count / all_combinations
return f"{round(p, 7)}"
if __name__ == "__main__":
solution = euler_205()
print("e205.py: " + str(solution))
# assert(solution == 0)