You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
1.1 KiB

lines = [[int(n) for n in l.split()] for l in open("input.txt", 'r').read().splitlines()]
unsafe, unsafe2 = 0, 0
def checksafe(report, recursive):
global unsafe, unsafe2
trend = -1 if report[0] > report[1] else 1
for i in range(len(report) -1):
if (trend == -1 and report[i] < report[i+1]) \
or (trend == 1 and report[i] > report[i+1]) \
or (report[i] == report[i+1]) \
or (abs(report[i] - report[i+1]) > 3):
if recursive:
return False
else:
unsafe += 1
# ????????? there's no way this is how this is should be done
if not (checksafe(l[:i-1] + l[i:], True) or checksafe(l[:i] + l[i+1:], True) or checksafe(l[:i+1] + l[i+2:], True)):
unsafe2 += 1
return False
return True
return True
for l in lines:
if l[0] == l[1]:
unsafe += 1
if not (checksafe(l[1:], True) or checksafe(l[:1] + l[2:], True)):
unsafe2 += 1
continue
else:
checksafe(l, False)
print(len(lines)-unsafe)
print(len(lines)-unsafe2)