day02: more code beautification
This commit is contained in:
parent
2431b0fd8d
commit
5904ced66b
20
day02.py
20
day02.py
@ -3,17 +3,15 @@ from typing import Any, List
|
|||||||
|
|
||||||
|
|
||||||
def follow_directions(path: List) -> (int, int, int):
|
def follow_directions(path: List) -> (int, int, int):
|
||||||
pos = 0
|
pos = depth = aim = 0
|
||||||
depth = 0
|
for direction, value in path:
|
||||||
aim = 0
|
if direction == 'forward':
|
||||||
for direction in path:
|
pos += value
|
||||||
if direction[0] == 'forward':
|
depth += aim * value
|
||||||
pos += direction[1]
|
elif direction == 'down':
|
||||||
depth += aim * direction[1]
|
aim += value
|
||||||
elif direction[0] == 'down':
|
elif direction == 'up':
|
||||||
aim += direction[1]
|
aim -= value
|
||||||
elif direction[0] == 'up':
|
|
||||||
aim -= direction[1]
|
|
||||||
|
|
||||||
return pos, depth, aim
|
return pos, depth, aim
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user