File tree 3 files changed +24
-2
lines changed
3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change
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 " )
Original file line number Diff line number Diff line change 1
1
<!-- AOC TILES BEGIN -->
2
2
<h1 align =" center " >
3
- Advent of Code - 218/458 ⭐
3
+ Advent of Code - 220/460 ⭐
4
4
</h1 >
5
5
<h1 align =" center " >
6
- 2024 - 8 ⭐ - Python
6
+ 2024 - 10 ⭐ - Python
7
7
</h1 >
8
8
<a href =" 2024/01/01.py " >
9
9
<img src =" .aoc_tiles/tiles/2024/01.png " width =" 161px " >
17
17
<a href =" 2024/04/04.py " >
18
18
<img src =" .aoc_tiles/tiles/2024/04.png " width =" 161px " >
19
19
</a >
20
+ <a href =" 2024/05/05.py " >
21
+ <img src =" .aoc_tiles/tiles/2024/05.png " width =" 161px " >
22
+ </a >
20
23
<h1 align =" center " >
21
24
2023 - 50 ⭐ - Python
22
25
</h1 >
You can’t perform that action at this time.
0 commit comments