day 2
parent
a2143ba7ae
commit
d610807879
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,6 @@
|
|||
7 6 4 2 1
|
||||
1 2 7 8 9
|
||||
9 7 6 2 1
|
||||
1 3 2 4 5
|
||||
8 6 4 4 1
|
||||
1 3 6 7 9
|
|
@ -0,0 +1,26 @@
|
|||
def solve(f):
|
||||
t = 0
|
||||
extra = 0
|
||||
for line in f:
|
||||
report = [int(x) for x in line.split()]
|
||||
safe = issafe(report)
|
||||
t += int(safe)
|
||||
if not safe:
|
||||
for i in range(len(report)):
|
||||
if issafe(report[:i] + report[i+1:]):
|
||||
extra += 1
|
||||
break
|
||||
|
||||
print(t)
|
||||
print(t + extra)
|
||||
|
||||
def issafe(report):
|
||||
d = [y-x for x,y in zip(report,report[1:])]
|
||||
if all(1<=x<=3 for x in d):
|
||||
return True
|
||||
if all(-3<=x<=-1 for x in d):
|
||||
return True
|
||||
return False
|
||||
|
||||
solve(open("sample1.in"))
|
||||
solve(open("input"))
|
Loading…
Reference in New Issue