From 5904ced66bcb952d8092208b5e627743d7fe5075 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Thu, 2 Dec 2021 07:04:56 +0100 Subject: [PATCH] day02: more code beautification --- day02.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/day02.py b/day02.py index 98bf72e..161bf4b 100644 --- a/day02.py +++ b/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