day02: more code beautification

This commit is contained in:
Stefan Harmuth 2021-12-02 07:04:56 +01:00
parent 2431b0fd8d
commit 5904ced66b

View File

@ -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