mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Minor fixes
This commit is contained in:
@@ -22,11 +22,11 @@ from aoc import days
|
|||||||
@click.argument("day", required=True)
|
@click.argument("day", required=True)
|
||||||
def main(day: int, timing: bool, data: IO[str]) -> None:
|
def main(day: int, timing: bool, data: IO[str]) -> None:
|
||||||
runner_class = days.get_runner(day)
|
runner_class = days.get_runner(day)
|
||||||
data = data.read()
|
contents = data.read()
|
||||||
|
|
||||||
start = time.perf_counter_ns()
|
start = time.perf_counter_ns()
|
||||||
|
|
||||||
part1, part2 = runner_class.run_both(data)
|
part1, part2 = runner_class.run_both(contents)
|
||||||
|
|
||||||
if timing:
|
if timing:
|
||||||
elapsed = time.perf_counter_ns() - start
|
elapsed = time.perf_counter_ns() - start
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ from . import CombinedRunner
|
|||||||
class DayRunner(CombinedRunner):
|
class DayRunner(CombinedRunner):
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_both(cls, data: str) -> tuple[Any, Any]:
|
def run_both(cls, data: str) -> tuple[Any, Any]:
|
||||||
data = StringIO(data)
|
nums = numpy.loadtxt(StringIO(data), dtype=numpy.int32)
|
||||||
nums = numpy.loadtxt(data, dtype=numpy.int32)
|
|
||||||
|
|
||||||
left = nums[..., 0]
|
left = nums[..., 0]
|
||||||
right = nums[..., 1]
|
right = nums[..., 1]
|
||||||
@@ -21,7 +20,7 @@ class DayRunner(CombinedRunner):
|
|||||||
|
|
||||||
diff = numpy.abs(left - right).sum()
|
diff = numpy.abs(left - right).sum()
|
||||||
|
|
||||||
counts = defaultdict(int)
|
counts: defaultdict[int, int] = defaultdict(int)
|
||||||
for val in right:
|
for val in right:
|
||||||
counts[val] += 1
|
counts[val] += 1
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ import os
|
|||||||
|
|
||||||
from aoc.days.day1 import DayRunner
|
from aoc.days.day1 import DayRunner
|
||||||
|
|
||||||
|
|
||||||
def get_data() -> str:
|
def get_data() -> str:
|
||||||
sample = os.path.dirname(__file__) + "/samples/01.txt"
|
sample = os.path.dirname(__file__) + "/samples/01.txt"
|
||||||
with open(sample, mode="rt", encoding="utf-8") as f:
|
with open(sample, mode="rt", encoding="utf-8") as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
def test_sample_part1():
|
|
||||||
|
def test_sample_part1() -> None:
|
||||||
assert DayRunner.part1(get_data()) == 11
|
assert DayRunner.part1(get_data()) == 11
|
||||||
|
|
||||||
def test_sample_part2():
|
|
||||||
|
def test_sample_part2() -> None:
|
||||||
assert DayRunner.part2(get_data()) == 31
|
assert DayRunner.part2(get_data()) == 31
|
||||||
|
|||||||
Reference in New Issue
Block a user