33 lines
771 B
Python
33 lines
771 B
Python
from lib import get_data
|
|
from collections import defaultdict
|
|
from itertools import permutations
|
|
|
|
data = get_data(__file__).strip()
|
|
|
|
pairs = defaultdict(int)
|
|
people = set()
|
|
|
|
for line in data.splitlines():
|
|
a, _, gainlose, amount, _, _, _, _, _, _, b = line[:-1].split()
|
|
amount = int(amount)
|
|
if gainlose == "lose":
|
|
amount = -amount
|
|
pairs[(a, b)] = amount
|
|
people.add(a)
|
|
|
|
|
|
def calc_gain(people):
|
|
maxgain = 0
|
|
for xs in permutations(list(people)):
|
|
gain = 0
|
|
for i in range(len(xs)):
|
|
gain += pairs[(xs[i], xs[(i + 1) % len(xs)])]
|
|
gain += pairs[(xs[(i + 1) % len(xs)], xs[i])]
|
|
maxgain = max(maxgain, gain)
|
|
return maxgain
|
|
|
|
|
|
print(calc_gain(people))
|
|
people.add("Felix")
|
|
print(calc_gain(people))
|