#!/usr/bin/env python # 2024 - Advent Of Code 2 # file = 'input_example.txt' file = 'input.txt' # pylint: disable=consider-using-with input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")] safe = 0 for reports in input_lines: levels = [ int(r) for r in reports.split(' ') ] # print(f'{levels=}') s_diff = 0 if levels[0] > levels[1] else 1 break_diff = False for l in range(1, len(levels)): diff = levels[l] - levels[l-1] if abs(diff) > 3 or diff == 0: break_diff = True break s_diff2 = 0 if levels[l] < levels[l-1] else 1 if s_diff ^ s_diff2 != 0: # print("sign change") break_diff = True break if not break_diff: # print("safe") safe += 1 print(f'{safe=}')