35 lines
669 B
Python
35 lines
669 B
Python
|
|
from output import ints
|
||
|
|
|
||
|
|
|
||
|
|
def solve(data):
|
||
|
|
reports = [ints(line) for line in data.splitlines()]
|
||
|
|
p1 = 0
|
||
|
|
p2 = 0
|
||
|
|
|
||
|
|
for report in reports:
|
||
|
|
if issafe(report):
|
||
|
|
p1 += 1
|
||
|
|
|
||
|
|
for i in range(len(report)):
|
||
|
|
if issafe(report[:i] + report[i + 1 :]):
|
||
|
|
p2 += 1
|
||
|
|
break
|
||
|
|
|
||
|
|
return p1, p2
|
||
|
|
|
||
|
|
|
||
|
|
def issafe(report):
|
||
|
|
diffs = [a - b for a, b in zip(report, report[1:])]
|
||
|
|
|
||
|
|
return all(-3 <= d <= -1 for d in diffs) or all(1 <= d <= 3 for d in diffs)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
with open("./input/02.txt", "r") as f:
|
||
|
|
inp = f.read().strip()
|
||
|
|
|
||
|
|
p1, p2 = solve(inp)
|
||
|
|
|
||
|
|
print(p1)
|
||
|
|
print(p2)
|