Last active
January 6, 2018 16:29
-
-
Save vladris/73e4f89d2f2011b4c86fea70a290725c to your computer and use it in GitHub Desktop.
Solution for Adevent of Code 2017/Day 24
This file contains 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
components = [tuple(map(int, line.strip().split('/'))) for line in open("input.txt").readlines()] | |
def best_bridge(end, components): | |
result = 0 | |
for i, c in enumerate(components): | |
if end == c[0]: | |
new_end = c[1] | |
elif end == c[1]: | |
new_end = c[0] | |
else: | |
continue | |
result = max(result, end + new_end + best_bridge(new_end, components[:i] + components[i+1:])) | |
return result | |
print(best_bridge(0, components)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem statement: http://adventofcode.com/2017/day/24