generated from public/aoc_template
52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
import sys
|
|
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(6, "input19_test"),
|
|
(296, "input19"),
|
|
],
|
|
[
|
|
(16, "input19_test"),
|
|
(619970556776002, "input19"),
|
|
],
|
|
]
|
|
|
|
def parse_input(self) -> tuple[list[str], list[str]]:
|
|
towels, designs = self.getMultiLineInputAsArray()
|
|
return [x for x in towels[0].split(", ")], designs
|
|
|
|
def get_options(self, design: str, towels: list[str], part2: bool = False) -> int:
|
|
if not design:
|
|
return 1
|
|
|
|
if design in self.DP:
|
|
return self.DP[design]
|
|
|
|
options = 0
|
|
for towel in towels:
|
|
if design.startswith(towel):
|
|
options += self.get_options(design[len(towel) :], towels, part2)
|
|
if not part2 and options > 0:
|
|
return 1
|
|
|
|
self.DP[design] = options
|
|
|
|
return options
|
|
|
|
def part1(self) -> Any:
|
|
towels, designs = self.parse_input()
|
|
return sum(self.get_options(design, towels, part2=False) > 0 for design in designs)
|
|
|
|
def part2(self) -> Any:
|
|
towels, designs = self.parse_input()
|
|
return sum(self.get_options(design, towels, part2=True) for design in designs)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
day = Day(2024, 19)
|
|
day.run(verbose=True)
|