File tree 3 files changed +1274
-1
lines changed
3 files changed +1274
-1
lines changed Original file line number Diff line number Diff line change
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 ))
You can’t perform that action at this time.
0 commit comments