lots of cleanup
This commit is contained in:
parent
7d0d3e504e
commit
0385cbd62e
26 changed files with 337 additions and 417 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
|
||||
from typing import Iterator
|
||||
from typing import Iterator, Self
|
||||
|
||||
day_num = 4
|
||||
|
||||
|
|
@ -19,10 +19,10 @@ class Range:
|
|||
start: int
|
||||
end: int
|
||||
|
||||
@staticmethod
|
||||
def parse(line: str) -> Range:
|
||||
@classmethod
|
||||
def parse(cls, line: str) -> Self:
|
||||
match line.split('-'):
|
||||
case [s, e]: return Range(int(s), int(e))
|
||||
case [s, e]: return cls(int(s), int(e))
|
||||
case _: raise Exception(f"Not a valid range: {line}")
|
||||
|
||||
def includes(self, other: Range) -> bool:
|
||||
|
|
@ -39,10 +39,10 @@ class Pair:
|
|||
first: Range
|
||||
second: Range
|
||||
|
||||
@staticmethod
|
||||
def parse(line: str) -> Pair:
|
||||
@classmethod
|
||||
def parse(cls, line: str) -> Self:
|
||||
match line.split(','):
|
||||
case [f, s]: return Pair(Range.parse(f), Range.parse(s))
|
||||
case [f, s]: return cls(Range.parse(f), Range.parse(s))
|
||||
case _: raise Exception(f"Not a valid Pair: {line}")
|
||||
|
||||
def includes(self) -> bool:
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
from advent.common import utils
|
||||
from advent.common import input
|
||||
|
||||
from .solution import Pair, Range, day_num, part1, part2
|
||||
|
||||
|
||||
def test_part1():
|
||||
data = utils.read_data(day_num, 'test01.txt')
|
||||
data = input.read_lines(day_num, 'test01.txt')
|
||||
expected = 2
|
||||
result = part1(data)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_part2():
|
||||
data = utils.read_data(day_num, 'test01.txt')
|
||||
data = input.read_lines(day_num, 'test01.txt')
|
||||
expected = 4
|
||||
result = part2(data)
|
||||
assert result == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue