initial commit, day 10
This commit is contained in:
19
02a.py
Executable file
19
02a.py
Executable file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
|
||||
print(sum(test_report(x) for x in reports))
|
||||
Reference in New Issue
Block a user