From 3b3ea454f3443a31837cee9c36e88216b9efc28b Mon Sep 17 00:00:00 2001 From: vsedov Date: Thu, 5 Dec 2024 13:32:06 +0000 Subject: [PATCH] day 05 cleanup --- src/aoc/aoc2024/day_05.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/aoc/aoc2024/day_05.py b/src/aoc/aoc2024/day_05.py index 33afb6f..a6c2fb9 100644 --- a/src/aoc/aoc2024/day_05.py +++ b/src/aoc/aoc2024/day_05.py @@ -50,18 +50,18 @@ def find_valid_order(deps: npt.NDArray, numbers: npt.NDArray) -> npt.NDArray: return result -def parse(txt: str) -> Tuple[npt.NDArray, npt.NDArray]: +def parse(txt: str) -> Tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: rules_txt, sequences_txt = txt.split("\n\n") - rules = np.array( - [[int(x) for x in line.split("|")] for line in rules_txt.splitlines()], - dtype=np.int64, - ) - sequences = [] - for line in sequences_txt.splitlines(): - seq = np.fromstring(line, sep=",", dtype=np.int64) - sequences.append(seq) - return rules, np.array(sequences, dtype=object) + return np.array( + [line.split("|") for line in rules_txt.splitlines()], dtype=np.int64 + ), np.array( + [ + np.fromstring(line, sep=",", dtype=np.int64) + for line in sequences_txt.splitlines() + ], + dtype=object, + ) def part_a(txt: str) -> int: