Skip to content

Commit e81d9df

Browse files
committedDec 25, 2023
feat: 2023 day 25
1 parent 0b3281e commit e81d9df

File tree

3 files changed

+1274
-1
lines changed

3 files changed

+1274
-1
lines changed
 

‎2023/25.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from aoc import *
2+
from collections import defaultdict
3+
from graphviz import Graph
4+
5+
6+
def search(node, m, visited):
7+
if node in visited:
8+
return
9+
visited.add(node)
10+
for n in m[node]:
11+
search(n, m, visited)
12+
13+
14+
def main(input_file: str):
15+
inp = lines(input_file)
16+
dot = Graph()
17+
m = defaultdict(set)
18+
for l in inp:
19+
left, right = l.rstrip().split(': ')
20+
right = right.split()
21+
dot.node(left)
22+
for r in right:
23+
dot.node(r)
24+
dot.edge(left, r)
25+
26+
# These were added after inspecting the graph, see below.
27+
if (
28+
r == 'gbc'
29+
and left == 'hxr'
30+
or r == 'hxr'
31+
and left == 'gbc'
32+
or r == 'mvv'
33+
and left == 'xkz'
34+
or r == 'xkz'
35+
and left == 'mvv'
36+
or r == 'tmt'
37+
and left == 'pnz'
38+
or r == 'pnz'
39+
and left == 'tmt'
40+
):
41+
continue
42+
m[r].add(left)
43+
m[left].add(r)
44+
45+
# Store the graph as svg and identify nodes needed in Inkscape
46+
# dot.format = 'svg'
47+
# dot.render('25.dot')
48+
49+
v = set()
50+
search('mvv', m, v)
51+
a = len(v)
52+
v = set()
53+
search('xkz', m, v)
54+
b = len(v)
55+
return a * b
56+
57+
58+
DAY = 25
59+
FILE = f"{DAY}.txt"
60+
print(main(FILE))

0 commit comments

Comments
 (0)