day 13, brut force all permutations
This commit is contained in:
parent
6eff8af332
commit
5c6f10c81e
|
@ -0,0 +1,26 @@
|
||||||
|
import sys, os
|
||||||
|
from collections import defaultdict as dd
|
||||||
|
from itertools import permutations as PERM
|
||||||
|
|
||||||
|
N:set[str] = set()
|
||||||
|
D:dict[tuple[str,str],int] = dd(int)
|
||||||
|
|
||||||
|
for l in sys.stdin.readlines():
|
||||||
|
[a,s,b] = l[:-1].split(" ")
|
||||||
|
D[(a,b)] += int(s)
|
||||||
|
D[(b,a)] += int(s)
|
||||||
|
N.add(a)
|
||||||
|
N.add(b)
|
||||||
|
|
||||||
|
if len(sys.argv)>1 and sys.argv[1]=="2":
|
||||||
|
# add you
|
||||||
|
for a in N:
|
||||||
|
D[(a,'Y')] = 0
|
||||||
|
D[('Y',a)] = 0
|
||||||
|
N.add('Y')
|
||||||
|
|
||||||
|
def score(chain:list[str]) -> int:
|
||||||
|
return sum(D[(a,b)] for (a,b) in zip(chain, chain[1:])) \
|
||||||
|
+ D[(chain[0],chain[-1])]
|
||||||
|
|
||||||
|
print(max(score(p) for p in PERM(N)))
|
Loading…
Reference in New Issue