Skip to content

Instantly share code, notes, and snippets.

@BeyondEvil
Created December 24, 2017 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeyondEvil/92b0df4e353e5ec8119c15edca8ad700 to your computer and use it in GitHub Desktop.
Save BeyondEvil/92b0df4e353e5ec8119c15edca8ad700 to your computer and use it in GitHub Desktop.
import networkx as nx
def read_input():
with open('input.txt', 'r') as f:
return f.read().strip()
def get_strength(graph, path):
return graph.subgraph(path).size('weight')
def run_it(seq):
graph = nx.Graph()
start = 0
end = 0
nodes = set()
for each in seq.split('\n'):
p_a, p_b = each.split('/')
p_a = int(p_a)
p_b = int(p_b)
nodes.add(p_a)
nodes.add(p_b)
if p_a >= end:
end = p_a
if p_b >= end:
end = p_b
graph.add_edge(p_a, p_b, weight=(p_a + p_b))
graph.add_edge(p_b, p_a, weight=(p_a + p_b))
strengths = []
for node in nodes:
for path in nx.all_simple_paths(graph, start, node):
strengths.append(get_strength(graph, path))
print max(strengths)
print('Part 1: ', 0)
print('Part 2: ', 0)
if __name__ == '__main__':
run_it(read_input()) # ,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment