add: part2
This commit is contained in:
		
							
								
								
									
										18
									
								
								2023/day02/src/part2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								2023/day02/src/part2.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
text: str = open("input.txt", "r").read()
 | 
			
		||||
 | 
			
		||||
import math
 | 
			
		||||
 | 
			
		||||
value: int = 0
 | 
			
		||||
 | 
			
		||||
for line in text.split("\n"):
 | 
			
		||||
	ok = 0
 | 
			
		||||
	game = line.split(": ")
 | 
			
		||||
	bozo_dict: dict = {}
 | 
			
		||||
	for bozo_set in game[1].split("; "):
 | 
			
		||||
		for cube in bozo_set.split(", "):
 | 
			
		||||
			values = cube.split(" ")
 | 
			
		||||
			if (bozo_dict.get(values[1], 0) < int(values[0])):
 | 
			
		||||
				bozo_dict.update({values[1]: int(values[0])})
 | 
			
		||||
	value += math.prod(bozo_dict.values())
 | 
			
		||||
 | 
			
		||||
print(value)
 | 
			
		||||
		Reference in New Issue
	
	Block a user