generated from public/aoc_template
Compare commits
2 Commits
6bc0aa2f0c
...
694f9c6db9
| Author | SHA1 | Date | |
|---|---|---|---|
| 694f9c6db9 | |||
| a8c9f95582 |
BIN
.aoc_tiles/tiles/2024/01.png
Normal file
BIN
.aoc_tiles/tiles/2024/01.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
BIN
.aoc_tiles/tiles/2024/02.png
Normal file
BIN
.aoc_tiles/tiles/2024/02.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
@ -1,4 +1,13 @@
|
|||||||
# Advent of Code 2024
|
# Advent of Code 2024
|
||||||
|
|
||||||
<!-- AOC TILES BEGIN -->
|
<!-- AOC TILES BEGIN -->
|
||||||
|
<h1 align="center">
|
||||||
|
2024 - 4 ⭐ - Python
|
||||||
|
</h1>
|
||||||
|
<a href="day01.py">
|
||||||
|
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
|
||||||
|
</a>
|
||||||
|
<a href="day02.py">
|
||||||
|
<img src=".aoc_tiles/tiles/2024/02.png" width="161px">
|
||||||
|
</a>
|
||||||
<!-- AOC TILES END -->
|
<!-- AOC TILES END -->
|
||||||
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