day 15, shame to hardcode loop but fast enough
This commit is contained in:
		
							
								
								
									
										40
									
								
								d15/run.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								d15/run.py
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
		Reference in New Issue
	
	Block a user