day02: code beautification
This commit is contained in:
parent
a0b4513d31
commit
2431b0fd8d
40
day02.py
40
day02.py
@ -1,27 +1,8 @@
|
||||
from aoc import AOCDay
|
||||
from typing import Any
|
||||
from typing import Any, List
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
test_solutions_p1 = [150]
|
||||
test_solutions_p2 = [900]
|
||||
|
||||
def part1(self) -> Any:
|
||||
path = self.getInputAsArraySplit(" ", [str, int])
|
||||
pos = 0
|
||||
depth = 0
|
||||
for direction in path:
|
||||
if direction[0] == 'forward':
|
||||
pos += direction[1]
|
||||
elif direction[0] == 'down':
|
||||
depth += direction[1]
|
||||
elif direction[0] == 'up':
|
||||
depth -= direction[1]
|
||||
|
||||
return pos * depth
|
||||
|
||||
def part2(self) -> Any:
|
||||
path = self.getInputAsArraySplit(" ", [str, int])
|
||||
def follow_directions(path: List) -> (int, int, int):
|
||||
pos = 0
|
||||
depth = 0
|
||||
aim = 0
|
||||
@ -34,4 +15,21 @@ class Day(AOCDay):
|
||||
elif direction[0] == 'up':
|
||||
aim -= direction[1]
|
||||
|
||||
return pos, depth, aim
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
test_solutions_p1 = [150]
|
||||
test_solutions_p2 = [900]
|
||||
|
||||
def part1(self) -> Any:
|
||||
path = self.getInputAsArraySplit(" ", [str, int])
|
||||
pos, _, depth = follow_directions(path)
|
||||
|
||||
return pos * depth
|
||||
|
||||
def part2(self) -> Any:
|
||||
path = self.getInputAsArraySplit(" ", [str, int])
|
||||
pos, depth, _ = follow_directions(path)
|
||||
|
||||
return pos * depth
|
||||
|
||||
Loading…
Reference in New Issue
Block a user