Skip to content

Instantly share code, notes, and snippets.

@bclavie
Created December 6, 2019 10:42
Show Gist options
  • Save bclavie/a170c703ab981385d756a3ce16ea2ea7 to your computer and use it in GitHub Desktop.
Save bclavie/a170c703ab981385d756a3ce16ea2ea7 to your computer and use it in GitHub Desktop.
# Please use the following encoding: utf-8, thanks!
import networkx as nx
''' Part 1'''
graph = nx.read_edgelist('./data/day6_input.txt', delimiter=')', create_using=nx.DiGraph)
orbit_count = sum(len(nx.ancestors(G=graph, source=node)) for node in graph.nodes)
print(orbit_count)
''' Part 2 '''
undir_graph = nx.read_edgelist('./data/day6_input.txt', delimiter=')', create_using=nx.Graph)
shortest = len(nx.shortest_path(undir_graph, source="YOU", target="SAN")) - 3
print(shortest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment