2015 day 20.

This commit is contained in:
Mikaël Capelle 2024-01-06 22:07:34 +01:00
parent cfa7718475
commit 57fcb47fe9
2 changed files with 29 additions and 0 deletions

View File

@ -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}")

View File

@ -0,0 +1 @@
34000000