Refactor code for API (#3)
Co-authored-by: Mikael CAPELLE <mikael.capelle@thalesaleniaspace.com> Co-authored-by: Mikaël Capelle <capelle.mikael@gmail.com> Reviewed-on: #3
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| import sys | ||||
| from typing import Iterator | ||||
| from typing import Any, Iterator | ||||
|  | ||||
| from ..base import BaseSolver | ||||
|  | ||||
|  | ||||
| def iter_combinations(value: int, containers: list[int]) -> Iterator[tuple[int, ...]]: | ||||
| @@ -16,15 +17,18 @@ def iter_combinations(value: int, containers: list[int]) -> Iterator[tuple[int, | ||||
|             yield (containers[i],) + combination | ||||
|  | ||||
|  | ||||
| containers = [int(c) for c in sys.stdin.read().split()] | ||||
| total = 25 if len(containers) <= 5 else 150 | ||||
| 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)] | ||||
|         combinations = [ | ||||
|             combination for combination in iter_combinations(total, containers) | ||||
|         ] | ||||
|  | ||||
| answer_1 = len(combinations) | ||||
| print(f"answer 1 is {answer_1}") | ||||
|         yield len(combinations) | ||||
|  | ||||
| min_containers = min(len(combination) for combination in combinations) | ||||
|  | ||||
| answer_2 = sum(1 for combination in combinations if len(combination) == min_containers) | ||||
| print(f"answer 2 is {answer_2}") | ||||
|         min_containers = min(len(combination) for combination in combinations) | ||||
|         yield sum( | ||||
|             1 for combination in combinations if len(combination) == min_containers | ||||
|         ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user