Skip to content

Instantly share code, notes, and snippets.

@BeyondEvil
Created December 30, 2017 16:13
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/b82d0e5ba4c0092a77cf592bb8483e83 to your computer and use it in GitHub Desktop.
Save BeyondEvil/b82d0e5ba4c0092a77cf592bb8483e83 to your computer and use it in GitHub Desktop.
import collections
def read_input():
with open('input.txt', 'r') as f:
return f.read().strip()
def build(components, curr_port, visited=None):
if visited is None:
visited = []
path = []
for c in components:
if curr_port == c[0] or curr_port == c[1]:
if c not in visited:
visited.append(c)
cp_comp = components[:]
cp_comp.remove(c)
x = list(c) + build(cp_comp, c[1] if c[0] == curr_port else c[0], visited)
path.append(x)
return path
def flatten(l):
for el in l:
if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
for sub in flatten(el):
yield sub
else:
yield el
def run_it(seq):
components = []
for node in seq.split('\n'):
p1, p2 = [int(p) for p in node.split('/')]
components.append((p1, p2))
bridges = build(components, 0)
sums = []
for bridge in bridges:
sums.append(sum(list(flatten(bridge))))
print max(sums)
print('Part 1: ', 0)
print('Part 2: ', 0)
if __name__ == '__main__':
_seq = """0/2
2/2
2/3
3/4
3/5
0/1
10/1
9/10"""
run_it(_seq)
run_it(read_input()) # ,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment