Solve 2015 days 11-14.
This commit is contained in:
35
2015/d13.py
Normal file
35
2015/d13.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from itertools import permutations
|
||||
data = open(0).read().strip()
|
||||
|
||||
part_2 = False
|
||||
|
||||
people = set()
|
||||
scores = {}
|
||||
for line in data.splitlines():
|
||||
a, _, wl, score, _, _, _, _, _, _, b = line.split()
|
||||
b = b.replace(".", "")
|
||||
score = int(score)
|
||||
if wl == "lose":
|
||||
score = -score
|
||||
people.add(a)
|
||||
people.add(b)
|
||||
scores[(a, b)] = score
|
||||
if part_2:
|
||||
scores[(a, "me")] = 0
|
||||
scores[("me", a)] = 0
|
||||
scores[(b, "me")] = 0
|
||||
scores[("me", b)] = 0
|
||||
|
||||
if part_2:
|
||||
people.add("me")
|
||||
|
||||
max_score = 0
|
||||
for p in permutations(list(people)):
|
||||
s = 0
|
||||
for i in range(len(p)):
|
||||
a, b = p[i], p[(i + 1) % len(p)]
|
||||
s += scores[(a, b)]
|
||||
s += scores[(b, a)]
|
||||
max_score = max(max_score, s)
|
||||
|
||||
print(max_score)
|
||||
Reference in New Issue
Block a user