From 0ac396c3c0e5db146b1ce9fb8f8bb5467745b60f Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 3 Dec 2024 11:45:31 -0800 Subject: [PATCH] Update parsing to use more generic parsers --- 2015/d02.py | 2 +- 2015/d20.py | 6 ------ 2016/assembunny.py | 3 +-- 2016/d12.py | 3 +-- 2017/d12.py | 2 +- 2017/d20.py | 2 +- 2018/d10.py | 1 - 2018/d11.py | 1 - 2019/d12.py | 1 - 2021/d17.py | 2 +- 10 files changed, 6 insertions(+), 17 deletions(-) diff --git a/2015/d02.py b/2015/d02.py index d5f0864..c1d96d7 100755 --- a/2015/d02.py +++ b/2015/d02.py @@ -18,7 +18,7 @@ class Day02(aoc.Challenge): aoc.TestCase(inputs=SAMPLE[0], part=2, want=34), aoc.TestCase(inputs=SAMPLE[1], part=2, want=14), ) - INPUT_PARSER = aoc.parse_re_findall_int(aoc.RE_INT) + INPUT_PARSER = aoc.parse_ints def part1(self, puzzle_input: InputType) -> int: """Return the amount of wrapping paper needed.""" diff --git a/2015/d20.py b/2015/d20.py index f6160a7..1aa695b 100755 --- a/2015/d20.py +++ b/2015/d20.py @@ -29,18 +29,12 @@ def prime_factors(num: int) -> list[int]: class Day20(aoc.Challenge): """Day 20: Infinite Elves and Infinite Houses.""" - DEBUG = True - # Default is True. On live solve, submit one tests pass. - # SUBMIT = {1: False, 2: False} - TESTS = [ aoc.TestCase(inputs=SAMPLE[0], part=1, want=4), aoc.TestCase(inputs=SAMPLE[1], part=1, want=8), aoc.TestCase(inputs=SAMPLE[0], part=2, want=aoc.TEST_SKIP), ] - INPUT_PARSER = aoc.parse_one_int - def part1(self, puzzle_input: InputType) -> int: target = puzzle_input // 10 diff --git a/2016/assembunny.py b/2016/assembunny.py index e044276..3c86573 100644 --- a/2016/assembunny.py +++ b/2016/assembunny.py @@ -32,8 +32,7 @@ class Assembunny: def __init__(self, instructions: list[str]): """Initialize, parse the instructions.""" inst = [] - for line in instructions: - instruction = line.split() + for instruction in instructions: inst.append([Operation[instruction[0].upper()].value] + instruction[1:]) self.instructions = inst self.instruction_count = len(instructions) diff --git a/2016/d12.py b/2016/d12.py index 7a6bb7b..9320a41 100755 --- a/2016/d12.py +++ b/2016/d12.py @@ -30,8 +30,7 @@ class Day12(aoc.Challenge): def solver(self, puzzle_input: list[str], param: bool) -> int: """Simulate a computer.""" instructions = [] - for line in puzzle_input: - instruction = line.split() + for instruction in puzzle_input: op_code = assembunny.Operation[instruction[0].upper()].value instructions.append([op_code] + instruction[1:]) end = len(instructions) diff --git a/2017/d12.py b/2017/d12.py index 80ba9ac..f51fa3c 100755 --- a/2017/d12.py +++ b/2017/d12.py @@ -21,7 +21,7 @@ class Day12(aoc.Challenge): aoc.TestCase(part=1, inputs=SAMPLE, want=6), aoc.TestCase(part=2, inputs=SAMPLE, want=2), ] - INPUT_PARSER = aoc.parse_ints_per_line + INPUT_PARSER = aoc.parse_ints def solver(self, puzzle_input: list[list[int]], part_one: bool) -> int: pipes = collections.defaultdict(set) diff --git a/2017/d20.py b/2017/d20.py index 605c21c..e970cc6 100755 --- a/2017/d20.py +++ b/2017/d20.py @@ -24,7 +24,7 @@ class Day20(aoc.Challenge): aoc.TestCase(part=1, inputs=SAMPLE[0], want=0), aoc.TestCase(part=2, inputs=SAMPLE[1], want=1), ] - INPUT_PARSER = aoc.parse_ints_per_line + INPUT_PARSER = aoc.parse_ints @staticmethod def distance(vals: tuple[int, ...]) -> int: diff --git a/2018/d10.py b/2018/d10.py index 84b0924..3643b00 100755 --- a/2018/d10.py +++ b/2018/d10.py @@ -48,7 +48,6 @@ class Day10(aoc.Challenge): aoc.TestCase(inputs=SAMPLE, part=1, want="HI"), aoc.TestCase(inputs=SAMPLE, part=2, want=3), ] - INPUT_PARSER = aoc.parse_ints def solver(self, puzzle_input: InputType, part_one: bool) -> int | str: """Return the message in the moving stars.""" diff --git a/2018/d11.py b/2018/d11.py index 47924e9..d23c146 100755 --- a/2018/d11.py +++ b/2018/d11.py @@ -15,7 +15,6 @@ class Day11(aoc.Challenge): aoc.TestCase(inputs=SAMPLE[0], part=2, want="90,269,16"), aoc.TestCase(inputs=SAMPLE[1], part=2, want="232,251,12"), ] - INPUT_PARSER = aoc.parse_one_int def solver(self, puzzle_input: int, part_one: bool) -> str: serial = puzzle_input diff --git a/2019/d12.py b/2019/d12.py index 5737697..d44c271 100755 --- a/2019/d12.py +++ b/2019/d12.py @@ -73,7 +73,6 @@ class Day12(aoc.Challenge): aoc.TestCase(inputs=SAMPLE[1], part=2, want=2772), aoc.TestCase(inputs=SAMPLE[2], part=2, want=4686774924), ) - INPUT_PARSER = aoc.parse_re_findall_int(aoc.RE_INT) def part1(self, puzzle_input: List[Tuple[int]]) -> int: """Run the similation for N cycles and return total energy at the end.""" diff --git a/2021/d17.py b/2021/d17.py index 3ba3de3..6201c55 100755 --- a/2021/d17.py +++ b/2021/d17.py @@ -14,7 +14,7 @@ class Day17(aoc.Challenge): aoc.TestCase(inputs=SAMPLE, part=1, want=45), aoc.TestCase(inputs=SAMPLE, part=2, want=112), ) - INPUT_PARSER = aoc.parse_re_group_int(r"target area: x=(-?\d+)..(-?\d+), y=(-?\d+)..(-?\d+)") + INPUT_PARSER = aoc.parse_ints def part1(self, puzzle_input: InputType) -> int: """Compute the highest height that can be reached while hitting the target."""