From 4bbea65adc31d259ae2fff63de3aedef6a4846dd Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Sun, 5 Dec 2021 14:37:48 -0500 Subject: [PATCH] Refactoring parsing and direction check --- puzzles/day05.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/puzzles/day05.py b/puzzles/day05.py index dda1e50..d30fce7 100644 --- a/puzzles/day05.py +++ b/puzzles/day05.py @@ -29,8 +29,10 @@ class VolcanicVent: end: Location def __post_init__(self): - if self.start.x == self.end.x or self.start.y == self.end.y: - self.direction = "vertical" if self.start.x == self.end.x else "horizontal" + if self.start.x == self.end.x: + self.direction = "vertical" + elif self.start.y == self.end.y: + self.direction = "horizontal" else: self.direction = "diagnal" @@ -90,12 +92,10 @@ def parse(inputs: str) -> List[int]: results = [] for line in inputs.split("\n"): start_end = line.split(" -> ") - start_split = start_end[0].split(",") - end_split = start_end[1].split(",") results.append( VolcanicVent( - start=Location(x=start_split[0], y=start_split[1]), - end=Location(x=end_split[0], y=end_split[1]), + start=Location(*start_end[0].split(",")), + end=Location(*start_end[1].split(",")), ) ) return results