|
|
@ -2,10 +2,8 @@ lines = [[int(n) for n in l.split()] for l in open("input.txt", 'r').read().spli |
|
|
|
|
|
|
|
|
|
|
|
unsafe, unsafe2 = 0, 0 |
|
|
|
unsafe, unsafe2 = 0, 0 |
|
|
|
|
|
|
|
|
|
|
|
for report in lines: |
|
|
|
def checksafe(report, recursive): |
|
|
|
if report[0] == report[1]: |
|
|
|
global unsafe, unsafe2 |
|
|
|
unsafe += 1 |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trend = -1 if report[0] > report[1] else 1 |
|
|
|
trend = -1 if report[0] > report[1] else 1 |
|
|
|
|
|
|
|
|
|
|
@ -14,8 +12,26 @@ for report in lines: |
|
|
|
or (trend == 1 and report[i] > report[i+1]) \ |
|
|
|
or (trend == 1 and report[i] > report[i+1]) \ |
|
|
|
or (report[i] == report[i+1]) \ |
|
|
|
or (report[i] == report[i+1]) \ |
|
|
|
or (abs(report[i] - report[i+1]) > 3): |
|
|
|
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 |
|
|
|
unsafe += 1 |
|
|
|
break |
|
|
|
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)-unsafe) |
|
|
|
|
|
|
|
print(len(lines)-unsafe2) |