advent-of-code/2024/2/one.py
2024-12-25 12:59:49 +01:00

27 lines
517 B
Python

#!/usr/bin/env python3
import sys
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
safe_num = 0
for line in lines:
report = [int(level) for level in line.split(" ")]
acc = sorted(report)
dec = acc[::-1]
if report != acc and report != dec:
continue
for i in range(len(report)-1):
diff = abs(report[i] - report[i+1])
if diff < 1 or diff > 3:
break
else:
safe_num += 1
print(safe_num)