2024 day 2 part 2 solved (?)

master
kwout 1 month ago
parent 91f8845a23
commit 06ae784a2b
  1. 32
      2024/2.py

@ -2,10 +2,8 @@ lines = [[int(n) for n in l.split()] for l in open("input.txt", 'r').read().spli
unsafe, unsafe2 = 0, 0
for report in lines:
if report[0] == report[1]:
unsafe += 1
continue
def checksafe(report, recursive):
global unsafe, unsafe2
trend = -1 if report[0] > report[1] else 1
@ -14,8 +12,26 @@ for report in lines:
or (trend == 1 and report[i] > report[i+1]) \
or (report[i] == report[i+1]) \
or (abs(report[i] - report[i+1]) > 3):
unsafe += 1
break
if recursive:
return False
else:
unsafe += 1
# ????????? there's no way this is how this is should be done
if not (checksafe(l[:i-1] + l[i:], True) or checksafe(l[:i] + l[i+1:], True) or checksafe(l[:i+1] + l[i+2:], True)):
unsafe2 += 1
return False
return True
return True
for l in lines:
if l[0] == l[1]:
unsafe += 1
if not (checksafe(l[1:], True) or checksafe(l[:1] + l[2:], True)):
unsafe2 += 1
continue
else:
checksafe(l, False)
print(len(lines)-unsafe)
print(len(lines)-unsafe)
print(len(lines)-unsafe2)
Loading…
Cancel
Save