41 lines
829 B
Python
41 lines
829 B
Python
""" day2 part 1 """
|
|
|
|
import fileinput
|
|
|
|
count = 0
|
|
|
|
def is_safe(report):
|
|
prev = report[0]
|
|
direction = None
|
|
safe = True
|
|
for item in report[1:]:
|
|
delta = item - prev
|
|
print(direction,delta)
|
|
|
|
if delta == 0 or delta > 3 or delta < -3:
|
|
print(f'unsafe (delta={delta})')
|
|
safe = False
|
|
break
|
|
|
|
if (direction is not None) and ((delta > 0) != (direction > 0)):
|
|
print(f'unsafe (delta={delta} dir={direction})')
|
|
safe = False
|
|
break
|
|
|
|
direction = delta
|
|
prev = item
|
|
|
|
return safe
|
|
|
|
def remove_one(report):
|
|
for i in range(len(report)):
|
|
yield report[:i] + report[i+1:]
|
|
|
|
for line in fileinput.input():
|
|
report = [int(x) for x in line.split()]
|
|
|
|
if is_safe(report):
|
|
count += 1
|
|
|
|
print(count)
|