adventOfCode/challenges/2021/12-passagePathing/graph.py
AKU e2a08ae5db
Add 2021-12 in Go (not Python this time!)
Signed-off-by: AKU <tom@tdpain.net>
2021-12-12 14:50:07 +00:00

20 lines
No EOL
540 B
Python

import networkx as nx
import matplotlib.pyplot as plt
edges = []
nodes = []
with open("input.txt") as f:
for line in f.read().strip().splitlines():
f, t = line.split("-")
edges.append((f,t))
for x in [f, t]:
if x not in nodes:
nodes.append(x)
graph = nx.Graph()
graph.add_edges_from(edges)
pos = nx.kamada_kawai_layout(graph)
nx.draw_networkx_nodes(graph, pos, nodelist=nodes)
nx.draw_networkx_labels(graph, pos)
nx.draw_networkx_edges(graph, pos, edgelist=graph.edges())
plt.show()