From 101f5d139e551f2f4bab787c7b4142b744a16ba2 Mon Sep 17 00:00:00 2001 From: felixm Date: Sun, 25 Feb 2024 13:12:46 +0100 Subject: [PATCH] Solve problem 205 because I like solving easy problems to boost my confidence. --- python/e205.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 python/e205.py diff --git a/python/e205.py b/python/e205.py new file mode 100644 index 0000000..aba9e76 --- /dev/null +++ b/python/e205.py @@ -0,0 +1,35 @@ +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) +