2024 day 2.
This commit is contained in:
parent
4dd2d5d9c9
commit
79cc208875
@ -1,10 +1,22 @@
|
||||
import sys
|
||||
|
||||
lines = sys.stdin.read().splitlines()
|
||||
|
||||
answer_1 = ...
|
||||
def is_safe(level: list[int]) -> bool:
|
||||
diff = [a - b for a, b in zip(level[:-1], level[1:], strict=True)]
|
||||
|
||||
answer_2 = ...
|
||||
return sum(d > 0 for d in diff) in (0, len(diff)) and all(
|
||||
1 <= abs(d) <= 3 for d in diff
|
||||
)
|
||||
|
||||
|
||||
def is_any_safe(level: list[int]) -> bool:
|
||||
return any(is_safe(level[:i] + level[i + 1 :]) for i in range(0, len(level)))
|
||||
|
||||
|
||||
levels = [[int(c) for c in r.split()] for r in sys.stdin.read().splitlines()]
|
||||
|
||||
answer_1 = sum(is_safe(level) for level in levels)
|
||||
answer_2 = sum(is_safe(level) or is_any_safe(level) for level in levels)
|
||||
|
||||
print(f"answer 1 is {answer_1}")
|
||||
print(f"answer 2 is {answer_2}")
|
||||
|
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
|
Loading…
Reference in New Issue
Block a user