You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
33 lines
1.0 KiB
import itertools
|
|
file = open('input.txt', 'r')
|
|
|
|
people = {}
|
|
results = []
|
|
|
|
for line in file:
|
|
splits = line.split(' ')
|
|
people.setdefault(splits[0], {'relationship' : {} })
|
|
name = splits[len(splits)-1].strip()
|
|
name = name.strip(".")
|
|
happiness = int(splits[3])
|
|
if splits[2] == "lose":
|
|
happiness = 0-happiness
|
|
|
|
people[splits[0]]['relationship'].setdefault(name, happiness)
|
|
|
|
people.setdefault("Me", {'relationship' : {} })
|
|
for name in people:
|
|
people["Me"]['relationship'].setdefault(name, 0)
|
|
people[name]['relationship'].setdefault("Me", 0)
|
|
|
|
print(people)
|
|
for perm in itertools.permutations(people):
|
|
happy = 0
|
|
for i in range(0, len(perm)-1):
|
|
happy += people[perm[i]]['relationship'][perm[i+1]]
|
|
happy += people[perm[i+1]]['relationship'][perm[i]]
|
|
happy += people[perm[len(perm)-1]]['relationship'][perm[0]]
|
|
happy += people[perm[0]]['relationship'][perm[len(perm)-1]]
|
|
results.append([happy, perm])
|
|
|
|
print( min(results), max(results) )
|