day 3
This commit is contained in:
		
							parent
							
								
									05174e324e
								
							
						
					
					
						commit
						232426c284
					
				|  | @ -0,0 +1,15 @@ | |||
| import aocd | ||||
| 
 | ||||
| import re | ||||
| 
 | ||||
| def mul(a, b): | ||||
|     return int(a)*int(b) | ||||
| 
 | ||||
| def solve(data): | ||||
|     return sum(mul(*match) for match in re.findall(r'mul\((\d+),(\d+)\)', data)) | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     solution = solve(aocd.get_data(year=2024, day=3)) | ||||
| 
 | ||||
|     print(solution) | ||||
|     aocd.submit(solution, year=2024, day=3, part='a') | ||||
|  | @ -0,0 +1,16 @@ | |||
| import aocd | ||||
| 
 | ||||
| import re | ||||
| 
 | ||||
| def mul(a, b): | ||||
|     return int(a)*int(b) | ||||
| 
 | ||||
| def solve(data): | ||||
|     data = ''.join(segment.split("don't()")[0] for segment in data.split('do()')) | ||||
|     return sum(mul(*match) for match in re.findall(r'mul\((\d+),(\d+)\)', data)) | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     solution = solve(aocd.get_data(year=2024, day=3)) | ||||
| 
 | ||||
|     print(solution) | ||||
|     aocd.submit(solution, year=2024, day=3, part='b') | ||||
		Loading…
	
		Reference in New Issue