initial commit, day 10
This commit is contained in:
25
02b.py
Executable file
25
02b.py
Executable file
@@ -0,0 +1,25 @@
|
||||
with open('02a.txt') as f:
|
||||
text = f.read().strip()
|
||||
|
||||
def make_report(line):
|
||||
return [int(x.strip()) for x in line.split()]
|
||||
|
||||
reports = [make_report(x) for x in text.split('\n')]
|
||||
|
||||
def test_report(report):
|
||||
if len(report) == 1:
|
||||
return True
|
||||
dir = 1 if report[1] - report[0] > 0 else -1
|
||||
for i in range(len(report)-1):
|
||||
diff = (report[i+1] - report[i]) * dir
|
||||
if diff < 1 or diff > 3:
|
||||
return False
|
||||
return True
|
||||
|
||||
def test_sub_reports(report):
|
||||
for i in range(len(report)):
|
||||
if test_report(report[:i] + report[i+1:]):
|
||||
return True
|
||||
return False
|
||||
|
||||
print(sum(test_sub_reports(x) for x in reports))
|
||||
Reference in New Issue
Block a user