Browse Source

Refactoring parsing and direction check

pull/5/head
Ryan Reed 3 years ago
parent
commit
4bbea65adc
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      puzzles/day05.py

+ 6
- 6
puzzles/day05.py View File

@ -29,8 +29,10 @@ class VolcanicVent:
end: Location end: Location
def __post_init__(self): 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: else:
self.direction = "diagnal" self.direction = "diagnal"
@ -90,12 +92,10 @@ def parse(inputs: str) -> List[int]:
results = [] results = []
for line in inputs.split("\n"): for line in inputs.split("\n"):
start_end = line.split(" -> ") start_end = line.split(" -> ")
start_split = start_end[0].split(",")
end_split = start_end[1].split(",")
results.append( results.append(
VolcanicVent( 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 return results


Loading…
Cancel
Save