Skip to content

Commit

Permalink
Day 19: code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardob90 committed Dec 19, 2024
1 parent 4a8c905 commit f2a1717
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
23 changes: 11 additions & 12 deletions 19/python/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
8 changes: 4 additions & 4 deletions 19/python/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f2a1717

Please sign in to comment.