Skip to content

Commit

Permalink
Update parsing to use more generic parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacG committed Dec 3, 2024
1 parent 083cd9e commit 0ac396c
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion 2015/d02.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
6 changes: 0 additions & 6 deletions 2015/d20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions 2016/assembunny.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions 2016/d12.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 2017/d12.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 2017/d20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion 2018/d10.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
1 change: 0 additions & 1 deletion 2018/d11.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion 2019/d12.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion 2021/d17.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 0ac396c

Please sign in to comment.