solve day 3 part 1

This commit is contained in:
Heiko Ludwig 2024-12-03 18:39:18 +01:00
parent 107af855b4
commit b65e1a3153
4 changed files with 47 additions and 0 deletions

27
day_03/program.py Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env python3
# https://adventofcode.com/2024/day/3
import re
def get_lines(filename: str) -> list:
with open(filename, "r") as file:
return [line.strip() for line in file.readlines()]
def main():
# lines = get_lines("sample-input.txt")
lines = get_lines("input.txt")
result_sum = 0
for line in lines:
matches = re.findall(r"mul\((\d+),(\d+)\)", line)
for match in matches:
result_sum += int(match[0]) * int(match[1])
print("Part 1: The sum of the results is", result_sum)
if __name__ == '__main__':
main()