diff --git a/python/e109.py b/python/e109.py new file mode 100644 index 0000000..9cddafa --- /dev/null +++ b/python/e109.py @@ -0,0 +1,73 @@ + +def all_singles(): + return list(range(1, 21)) + [25] + + +def all_doubles(): + return [n * 2 for n in range(1, 21)] + [50] + + +def all_triples(): + return [n * 3 for n in range(1, 21)] + + +def euler_109(): + count = 0 + target_score = 100 + for first in all_doubles(): + # D + if first < target_score: + count += 1 + + # D T + for second in all_triples(): + if first + second < target_score: + count += 1 + # D D + for second in all_doubles(): + if first + second < target_score: + count += 1 + # D S + for second in all_singles(): + if first + second < target_score: + count += 1 + + # D T D + for second in all_triples(): + for third in all_doubles(): + if first + second + third < target_score: + count += 1 + # D T S + for second in all_triples(): + for third in all_singles(): + if first + second + third < target_score: + count += 1 + # D D S + for second in all_doubles(): + for third in all_singles(): + if first + second + third < target_score: + count += 1 + + # D T T + for second in all_triples(): + for third in all_triples(): + if second >= third and first + second + third < target_score: + count += 1 + + # D D + for second in all_doubles(): + for third in all_doubles(): + if second >= third and first + second + third < target_score: + count += 1 + # S S + for second in all_singles(): + for third in all_singles(): + if second >= third and first + second + third < target_score: + count += 1 + return count + + +if __name__ == "__main__": + solution = euler_109() + print("e109.py: " + str(solution)) + assert(solution == 38182)