Created
December 24, 2017 15:08
-
-
Save BeyondEvil/92b0df4e353e5ec8119c15edca8ad700 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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