diff --git a/d13/run.py b/d13/run.py new file mode 100644 index 0000000..50026b6 --- /dev/null +++ b/d13/run.py @@ -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)))