34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
from typing import List, Optional
|
|
|
|
import networkx as nx
|
|
import matplotlib.pyplot as plt
|
|
|
|
from data import parse, Node
|
|
|
|
destinations, node_list = parse("input.txt")
|
|
|
|
starting_nodes = []
|
|
for node in node_list:
|
|
if node.is_A_node():
|
|
starting_nodes.append(node)
|
|
|
|
|
|
def add_node(node: Node, known_nodes: List[str], graph: nx.Graph, node_list:List[Node], predecessor: Optional[str] = None):
|
|
if node.value not in known_nodes:
|
|
known_nodes.append(node.value)
|
|
add_node(node.move_left(node_list), known_nodes, graph, node_list, predecessor=node.value)
|
|
graph.add_node(node.value)
|
|
if predecessor is not None:
|
|
graph.add_edge(predecessor, node.value)
|
|
add_node(node.move_right(node_list), known_nodes, graph, node_list, predecessor=node.value)
|
|
|
|
subplot_num=121
|
|
for node in starting_nodes:
|
|
current_node = node
|
|
known_nodes = []
|
|
G = nx.DiGraph()
|
|
add_node(node, known_nodes, G, node_list)
|
|
plt.subplot(subplot_num)
|
|
nx.draw(G)
|
|
subplot_num += 1
|
|
plt.show() |