Advertisement
Guest User

AoC2019

a guest
Dec 5th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import networkx as nx
  2. def solve(data):
  3.     lines = [i.split(")") for i in data.splitlines()]
  4.     G = nx.Graph()
  5.     nodes = set()
  6.     for line in lines:
  7.         G.add_edge(line[0], line[1])
  8.         G.add_edge(line[1], line[0])
  9.         nodes.add(line[0])
  10.         nodes.add(line[1])
  11.  
  12.     total = 0
  13.     for each in nodes:
  14.         total += nx.shortest_path_length(G, "COM", each)
  15.     print("Part1", total)
  16.     print("Part2", nx.shortest_path_length(G, "YOU", "SAN")-2)
  17. solve(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement