main
magical 2024-12-02 05:23:17 +00:00
parent a2143ba7ae
commit d610807879
3 changed files with 1032 additions and 0 deletions

1000
day02/input 100644

File diff suppressed because it is too large Load Diff

6
day02/sample1.in 100644
View File

@ -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

26
day02/sol.py 100644
View File

@ -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"))