From f4aa799bac48ccf7ab1eab9aed694380f1353a8c Mon Sep 17 00:00:00 2001 From: daviddoji Date: Sun, 7 Jun 2026 19:54:54 +0200 Subject: [PATCH] Remove redundancies --- src/Year_2015/P1.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Year_2015/P1.py b/src/Year_2015/P1.py index a9bc02d..abf721d 100644 --- a/src/Year_2015/P1.py +++ b/src/Year_2015/P1.py @@ -32,12 +32,12 @@ # To what floor do the instructions take Santa? with open("files/P1.txt") as f: - directions = [line for line in f.read().strip().split()] + directions = f.read().strip() def part_1() -> None: - up = int(directions[0].count("(")) - down = int(directions[0].count(")")) + up = directions.count("(") + down = directions.count(")") print(f"The floor is {up - down}") @@ -58,14 +58,15 @@ def part_1() -> None: def part_2() -> None: floor = 0 - for idx, char in enumerate(directions[0], start=1): + for idx, char in enumerate(directions, start=1): if char == "(": floor += 1 elif char == ")": floor -= 1 if floor == -1: print(f"The position is {idx}") - break + return + print("Basement was never reached!") if __name__ == "__main__":