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):
|
||||
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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user