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):
pos = 0
depth = 0
aim = 0
for direction in path:
if direction[0] == 'forward':
pos += direction[1]
depth += aim * direction[1]
elif direction[0] == 'down':
aim += direction[1]
elif direction[0] == 'up':
aim -= direction[1]
pos = depth = aim = 0
for direction, value in path:
if direction == 'forward':
pos += value
depth += aim * value
elif direction == 'down':
aim += value
elif direction == 'up':
aim -= value
return pos, depth, aim