From 0ee7546cd2cf9b60fc8564ddcc8b5223d2c15674 Mon Sep 17 00:00:00 2001 From: Heiko Ludwig Date: Tue, 3 Dec 2024 19:56:04 +0100 Subject: [PATCH] replace index-based for loop with iteration through zip --- day_02/program.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/day_02/program.py b/day_02/program.py index a85eb07..f02822f 100755 --- a/day_02/program.py +++ b/day_02/program.py @@ -18,13 +18,13 @@ def get_report_entries(lines: list) -> list: def is_safe_single(reports: list) -> bool: increasing = True decreasing = True - for i in range(len(reports) - 1): - distance = abs(reports[i] - reports[i + 1]) + for a, b in zip(reports, reports[1:]): + distance = abs(a - b) if distance == 0 or distance > 3: return False - if reports[i] > reports[i + 1]: + if a > b: increasing = False - if reports[i] < reports[i + 1]: + if a < b: decreasing = False return increasing or decreasing