27 lines
590 B
Python
Executable file
27 lines
590 B
Python
Executable file
#!/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()
|