19 lines
568 B
Python
19 lines
568 B
Python
|
import aocd
|
||
|
|
||
|
def parse_reports(data):
|
||
|
for line in data.split('\n'):
|
||
|
yield [int(level) for level in line.split()]
|
||
|
|
||
|
def is_safe(report):
|
||
|
pairs = list(zip(report[:-1], report[1:]))
|
||
|
diffs = [a-b for a,b in pairs]
|
||
|
return all(diff in (1, 2, 3) for diff in diffs) or all(diff in (-1, -2, -3) for diff in diffs)
|
||
|
|
||
|
def solve(data):
|
||
|
return sum(is_safe(report) for report in parse_reports(data))
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
solution = solve(aocd.get_data(year=2024, day=2))
|
||
|
|
||
|
print(solution)
|
||
|
aocd.submit(solution, year=2024, day=2, part='a')
|