advent-of-code/src/holt59/aoc/2015/day20.py
Mikaël Capelle 377e501d34
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
Start fixing 2015 for new API.
2024-12-08 12:13:41 +01:00

30 lines
696 B
Python

import itertools
from typing import Any, Iterator
from ..base import BaseSolver
def presents(n: int, elf: int, max: int) -> 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
class Solver(BaseSolver):
def solve(self, input: str) -> Iterator[Any]:
target = int(input)
yield next(n for n in itertools.count(1) if presents(n, 10, target) >= target)
yield next(n for n in itertools.count(1) if presents(n, 11, 50) >= target)