generated from public/aoc_template
day2
This commit is contained in:
parent
6bc0aa2f0c
commit
a8c9f95582
51
day02.py
Normal file
51
day02.py
Normal file
@ -0,0 +1,51 @@
|
||||
from tools.aoc import AOCDay
|
||||
from typing import Any
|
||||
|
||||
|
||||
def check_report(levels: list[int]) -> bool:
|
||||
safe = True
|
||||
mode = None
|
||||
for i, level in enumerate(levels):
|
||||
if i == 0: continue
|
||||
if i == 1: mode = level < levels[i - 1]
|
||||
|
||||
if not 1 <= abs(level - levels[i - 1]) <= 3 or mode != (level < levels[i - 1]):
|
||||
safe = False
|
||||
break
|
||||
|
||||
return safe
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
(2, "input2_test"),
|
||||
(680, "input2"),
|
||||
],
|
||||
[
|
||||
(4, "input2_test"),
|
||||
(710, "input2"),
|
||||
]
|
||||
]
|
||||
|
||||
def part1(self) -> Any:
|
||||
return sum(check_report(x) for x in self.getInputAsArraySplit(split_char=" ", return_type=int))
|
||||
|
||||
def part2(self) -> Any:
|
||||
safe = 0
|
||||
for report in self.getInputAsArraySplit(split_char=" ", return_type=int):
|
||||
if check_report(report):
|
||||
safe += 1
|
||||
continue
|
||||
|
||||
for x in range(len(report)):
|
||||
if check_report(report[:x] + report[x + 1:]):
|
||||
safe += 1
|
||||
break
|
||||
|
||||
return safe
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
day = Day(2024, 2)
|
||||
day.run(verbose=True)
|
||||
1000
inputs/input2
Normal file
1000
inputs/input2
Normal file
File diff suppressed because it is too large
Load Diff
6
inputs/input2_test
Normal file
6
inputs/input2_test
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user