-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path24a_aoc.py
More file actions
39 lines (33 loc) · 919 Bytes
/
24a_aoc.py
File metadata and controls
39 lines (33 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
ports = []
def main():
try:
while True:
process(raw_input())
except EOFError:
solve()
def process(arg):
ports.append(tuple(int(x) for x in arg.split("/")))
def solve():
print max(strength(bridge) for bridge in possible_bridges((0,),ports))
def strength(bridge):
return 2*sum(bridge)-bridge[0]-bridge[-1]
def possible_bridges(beginning,pieces):
bridges = [beginning]
#print beginning, pieces
if len(pieces)==0:
return bridges
for (x,y) in pieces:
if beginning[-1] == x:
new = beginning + (y,)
z = pieces[:]
z.remove((x,y))
bridges += possible_bridges(new, z)
elif beginning[-1] == y:
new = beginning + (x,)
z = pieces[:]
z.remove((x,y))
bridges += possible_bridges(new, z)
else:
pass
return bridges
main()