From f2a1717cd9ac79cc448c685a06e4139bfa80e5db Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Thu, 19 Dec 2024 22:17:40 +0100 Subject: [PATCH] Day 19: code reformat --- 19/python/solution.py | 23 +++++++++++------------ 19/python/test_solution.py | 8 ++++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/19/python/solution.py b/19/python/solution.py index c0fa409..1f76da0 100644 --- a/19/python/solution.py +++ b/19/python/solution.py @@ -61,30 +61,29 @@ def count(self, string: str) -> int: return self._dp_search(string, count=True) -def parse_data(puzzle_input: str) -> tuple[list[str], list[str]]: +def parse_data(puzzle_input: str) -> tuple[Trie, list[str]]: """Parse input data""" patterns, designs = puzzle_input.split("\n\n") - return patterns.split(", "), designs.splitlines() + patterns = patterns.split(", ") + trie = Trie() + trie.insert(*patterns) + return trie, designs.splitlines() -def part1(patterns: list[str], designs: list[str]) -> int: +def part1(patterns: Trie, designs: list[str]) -> int: """Solve part 1""" - trie = Trie() - trie.insert(*patterns) - return sum(trie.search(d) for d in designs) + return sum(patterns.search(d) for d in designs) -def part2(patterns: list[str], designs: list[str]) -> int: +def part2(patterns: Trie, designs: list[str]) -> int: """Solve part 2""" - trie = Trie() - trie.insert(*patterns) - return sum(trie.count(d) for d in designs) + return sum(patterns.count(d) for d in designs) def solve(puzzle_input: str) -> tuple[int, int]: """Solve the puzzle for the given input""" - data = parse_data(puzzle_input) - return part1(*data), part2(*data) + trie, designs = parse_data(puzzle_input) + return part1(trie, designs), part2(trie, designs) if __name__ == "__main__": diff --git a/19/python/test_solution.py b/19/python/test_solution.py index a8df406..be80191 100644 --- a/19/python/test_solution.py +++ b/19/python/test_solution.py @@ -24,10 +24,10 @@ def test_parse(example_data: str) -> None: def test_part1(example_data: str) -> None: - data = parse_data(example_data) - assert part1(*data) == 6 + trie, designs = parse_data(example_data) + assert part1(trie, designs) == 6 def test_part2(example_data: str) -> None: - data = parse_data(example_data) - assert part2(*data) == 16 + trie, designs = parse_data(example_data) + assert part2(trie, designs) == 16