From a2f903affceaffa138a2829392830178eea017e5 Mon Sep 17 00:00:00 2001 From: setop Date: Sat, 23 Nov 2024 02:02:04 +0100 Subject: [PATCH] day 15, shame to hardcode loop but fast enough --- d15/run.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 d15/run.py diff --git a/d15/run.py b/d15/run.py new file mode 100644 index 0000000..f4455f0 --- /dev/null +++ b/d15/run.py @@ -0,0 +1,40 @@ +from dataclasses import dataclass +import sys + +@dataclass +class Ing: + capacity: int + durability: int + flavor: int + texture: int + calorie: int + + def __add__(self, j): + return Ing(self.capacity+j.capacity,self.durability+j.durability, self.flavor+j.flavor, self.texture+j.texture,self.calorie+j.calorie) + + def pIng(self, p:int): + return Ing(self.capacity*p, self.durability*p, self.flavor*p, self.texture*p, self.calorie*p) + + def score(self): + if self.capacity<0 or self.durability<0 or self.flavor<0 or self.texture<0: + return 0 + return self.capacity * self.durability * self.flavor * self.texture + +L:list[Ing] = list() + +for l in sys.stdin.readlines(): + l = l.replace(",","").split(" ") + L.append(Ing(int(l[2]),int(l[4]),int(l[6]),int(l[8]),int(l[10]))) + +M1 = M2 = 0 +for p1 in range(1,98): + for p2 in range(1,98): + for p3 in range(1,98): + p4 = 100-(p1+p2+p3) + i:Ing = L[0].pIng(p1)+L[1].pIng(p2)+L[2].pIng(p3)+L[3].pIng(p4) + s = i.score() + M1 = max(M1, s) + if i.calorie == 500: + M2 = max(M2, s) + +print(M1, M2)