-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday24.py
More file actions
64 lines (46 loc) · 1.61 KB
/
day24.py
File metadata and controls
64 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from collections import defaultdict
import graphviz
def parse_graph(data: str) -> graphviz.Digraph:
first_part = True
graph = graphviz.Digraph()
outputs: dict[str, int] = {}
inputs: dict[str, list[int]] = defaultdict(list)
counter = 0
for line in data.splitlines():
line = line.strip()
if len(line) == 0:
first_part = False
continue
if first_part:
continue
for i, part in enumerate(line.split(" ")):
if i == 0 or i == 2:
inputs[part].append(counter)
elif i == 1:
graph.node(name=str(counter), label=part, shape="box")
elif i == 4:
outputs[part] = counter
counter += 1
for output in outputs.keys():
if not output.startswith("z"):
continue
inputs[output] = [counter]
graph.node(name=str(counter), label=output, shape="circle")
counter += 1
for input in inputs.keys():
if not input.startswith("x") and not input.startswith("y"):
continue
outputs[input] = counter
graph.node(name=str(counter), label=input, shape="circle")
counter += 1
for input, left_end_points in inputs.items():
right_end_point = outputs[input]
for left_end_point in left_end_points:
graph.edge(str(left_end_point), str(right_end_point), label=input)
return graph
def task01(data: str) -> str:
return "not implemented"
def task02(data: str) -> str:
graph = parse_graph(data)
graph.view()
return "Extract manually from graphviz"