From f9a7a56acfd9796b50befe55cc65ed0385d17678 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Sat, 2 Dec 2023 23:12:04 -0500 Subject: [PATCH] fix runner --- 2023/justfile | 5 +++-- 2023/python/_sample.py | 2 ++ 2023/python/day01.py | 3 ++- 2023/python/day02.py | 2 ++ 2023/python/shared.py | 17 ++++++++++++----- 2023/samples/day01.part1.txt | 4 ---- 2023/samples/day01.txt | 11 ++++------- 2023/samples/day01.txt.part2 | 7 +++++++ 8 files changed, 32 insertions(+), 19 deletions(-) delete mode 100644 2023/samples/day01.part1.txt create mode 100644 2023/samples/day01.txt.part2 diff --git a/2023/justfile b/2023/justfile index fddee6d..ca18851 100644 --- a/2023/justfile +++ b/2023/justfile @@ -7,6 +7,7 @@ new: touch full/day{{ DAY }}.txt touch samples/day{{ DAY }}.txt +run: + /usr/bin/env python3 python/day{{ DAY }}.py - - + diff --git a/2023/python/_sample.py b/2023/python/_sample.py index 0f81824..c3aea1e 100644 --- a/2023/python/_sample.py +++ b/2023/python/_sample.py @@ -18,6 +18,8 @@ def main(): with shared.elapsed_timer() as elapsed: part1(rows) print("🕒", elapsed()) + + rows = [row for row in shared.load_rows(1,True)] with shared.elapsed_timer() as elapsed: part2(rows) print("🕒", elapsed()) diff --git a/2023/python/day01.py b/2023/python/day01.py index 6667dcd..e089c3a 100644 --- a/2023/python/day01.py +++ b/2023/python/day01.py @@ -55,8 +55,9 @@ def part2(rows): def main(): rows = [row for row in shared.load_rows(1)] with shared.elapsed_timer() as elapsed: - #part1(rows) + part1(rows) print("🕒", elapsed()) + rows = [row for row in shared.load_rows(1, True)] with shared.elapsed_timer() as elapsed: part2(rows) print("🕒", elapsed()) diff --git a/2023/python/day02.py b/2023/python/day02.py index a26c3b1..d007d02 100644 --- a/2023/python/day02.py +++ b/2023/python/day02.py @@ -54,6 +54,8 @@ def main(): with shared.elapsed_timer() as elapsed: part1(rows) print("🕒", elapsed()) + + rows = [row for row in shared.load_rows(2, True)] with shared.elapsed_timer() as elapsed: part2(rows) print("🕒", elapsed()) diff --git a/2023/python/shared.py b/2023/python/shared.py index 3ad982a..7317895 100644 --- a/2023/python/shared.py +++ b/2023/python/shared.py @@ -30,11 +30,18 @@ def minmax(l): return min(l), max(l) -def load_rows(day): - return [row for row in load(day)] +def load_rows(day, part2=False): + return [row for row in load(day,part2)] -def load(day): +def load(day, part2=False): + if part2: + path = Path(get_fname(day)+".part2") + try: + return path.read_text().rstrip().split("\n") + except FileNotFoundError: + # No part 2 file, use first file + pass path = Path(get_fname(day)) return path.read_text().rstrip().split("\n") @@ -43,9 +50,9 @@ def get_fname(day: int) -> str: import sys if sys.argv[-1] == "--sample": - return f"../samples/day{day:02}.txt" + return f"samples/day{day:02}.txt" else: - return f"../full/day{day:02}.txt" + return f"full/day{day:02}.txt" ############# diff --git a/2023/samples/day01.part1.txt b/2023/samples/day01.part1.txt deleted file mode 100644 index 7bbc69a..0000000 --- a/2023/samples/day01.part1.txt +++ /dev/null @@ -1,4 +0,0 @@ -1abc2 -pqr3stu8vwx -a1b2c3d4e5f -treb7uchet diff --git a/2023/samples/day01.txt b/2023/samples/day01.txt index 41aa89c..7bbc69a 100644 --- a/2023/samples/day01.txt +++ b/2023/samples/day01.txt @@ -1,7 +1,4 @@ -two1nine -eightwothree -abcone2threexyz -xtwone3four -4nineeightseven2 -zoneight234 -7pqrstsixteen +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet diff --git a/2023/samples/day01.txt.part2 b/2023/samples/day01.txt.part2 new file mode 100644 index 0000000..41aa89c --- /dev/null +++ b/2023/samples/day01.txt.part2 @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen