Co-authored-by: Mikael CAPELLE <mikael.capelle@thalesaleniaspace.com> Co-authored-by: Mikaël Capelle <capelle.mikael@gmail.com> Reviewed-on: #3
35 lines
947 B
Python
35 lines
947 B
Python
from typing import Any, Iterator
|
|
|
|
from ..base import BaseSolver
|
|
|
|
|
|
def iter_combinations(value: int, containers: list[int]) -> Iterator[tuple[int, ...]]:
|
|
if value < 0:
|
|
return
|
|
|
|
if value == 0:
|
|
yield ()
|
|
|
|
for i in range(len(containers)):
|
|
for combination in iter_combinations(
|
|
value - containers[i], containers[i + 1 :]
|
|
):
|
|
yield (containers[i],) + combination
|
|
|
|
|
|
class Solver(BaseSolver):
|
|
def solve(self, input: str) -> Iterator[Any]:
|
|
containers = [int(c) for c in input.split()]
|
|
total = 25 if len(containers) <= 5 else 150
|
|
|
|
combinations = [
|
|
combination for combination in iter_combinations(total, containers)
|
|
]
|
|
|
|
yield len(combinations)
|
|
|
|
min_containers = min(len(combination) for combination in combinations)
|
|
yield sum(
|
|
1 for combination in combinations if len(combination) == min_containers
|
|
)
|