Skip to content

Commit e8cc040

Browse files
committed
Add day 5
1 parent f4dbe79 commit e8cc040

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

.aoc_tiles/tiles/2024/05.png

10.1 KB
Loading

2024/05/05.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
rules, pages = open(0).read().split("\n\n")
2+
rules = {tuple(r.split("|")) for r in rules.splitlines()}
3+
4+
s1 = s2 = 0
5+
for row in pages.splitlines():
6+
n = row.split(",")
7+
n2 = n[:]
8+
if all(n.index(b) < n.index(a) for b, a in rules if b in n and a in n):
9+
s1 += int(n[len(n)//2])
10+
else:
11+
new = []
12+
i = -1
13+
while n:
14+
i = (i + 1) % len(n)
15+
if all(b not in n or b in new for b, a in rules if n[i] == a):
16+
new.append(n.pop(i))
17+
s2 += int(new[len(new)//2])
18+
19+
print(s1, s2, sep="\n")

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!-- AOC TILES BEGIN -->
22
<h1 align="center">
3-
Advent of Code - 218/458
3+
Advent of Code - 220/460
44
</h1>
55
<h1 align="center">
6-
2024 - 8 ⭐ - Python
6+
2024 - 10 ⭐ - Python
77
</h1>
88
<a href="2024/01/01.py">
99
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
@@ -17,6 +17,9 @@
1717
<a href="2024/04/04.py">
1818
<img src=".aoc_tiles/tiles/2024/04.png" width="161px">
1919
</a>
20+
<a href="2024/05/05.py">
21+
<img src=".aoc_tiles/tiles/2024/05.png" width="161px">
22+
</a>
2023
<h1 align="center">
2124
2023 - 50 ⭐ - Python
2225
</h1>

0 commit comments

Comments
 (0)