Compare commits

...

2 Commits

Author SHA1 Message Date
694f9c6db9 day2 - tiles 2024-12-02 06:33:43 +01:00
a8c9f95582 day2 2024-12-02 06:32:02 +01:00
6 changed files with 1066 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

@ -1,4 +1,13 @@
# Advent of Code 2024
<!-- 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 -->

51
day02.py Normal file
View 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

File diff suppressed because it is too large Load Diff

6
inputs/input2_test Normal file
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