From 5c6f10c81e7f4e11fe46a4dd86cc1249d2d32b98 Mon Sep 17 00:00:00 2001 From: setop Date: Fri, 22 Nov 2024 23:57:44 +0100 Subject: [PATCH] day 13, brut force all permutations --- d13/run.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 d13/run.py 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)))