From 2597235d0ce52ff9d2542ae2f94752b0c185b8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 6 Jan 2024 22:07:34 +0100 Subject: [PATCH] 2015 day 20. --- src/holt59/aoc/2015/day20.py | 28 +++++++++++++++++++++ src/holt59/aoc/inputs/holt59/2015/day20.txt | 1 + 2 files changed, 29 insertions(+) create mode 100644 src/holt59/aoc/2015/day20.py create mode 100644 src/holt59/aoc/inputs/holt59/2015/day20.txt diff --git a/src/holt59/aoc/2015/day20.py b/src/holt59/aoc/2015/day20.py new file mode 100644 index 0000000..4eb3f71 --- /dev/null +++ b/src/holt59/aoc/2015/day20.py @@ -0,0 +1,28 @@ +import itertools +import sys + +target = int(sys.stdin.read()) + + +def presents(n: int, elf: int, max: int = target) -> int: + count = 0 + k = 1 + while k * k < n: + if n % k == 0: + if n // k <= max: + count += elf * k + if k <= max: + count += elf * (n // k) + k += 1 + + if k * k == n and k <= max: + count += elf * k + + return count + + +answer_1 = next(n for n in itertools.count(1) if presents(n, 10) >= target) +print(f"answer 1 is {answer_1}") + +answer_2 = next(n for n in itertools.count(1) if presents(n, 11, 50) >= target) +print(f"answer 2 is {answer_2}") diff --git a/src/holt59/aoc/inputs/holt59/2015/day20.txt b/src/holt59/aoc/inputs/holt59/2015/day20.txt new file mode 100644 index 0000000..c519ba7 --- /dev/null +++ b/src/holt59/aoc/inputs/holt59/2015/day20.txt @@ -0,0 +1 @@ +34000000