1
0

Adding day 3

This commit is contained in:
Nicolas Green 2024-12-04 11:26:11 -05:00
parent 15a9c968c8
commit 4ebe53ac4f
No known key found for this signature in database
6 changed files with 42 additions and 0 deletions

10
day3/part1.py Normal file
View File

@ -0,0 +1,10 @@
import re
result = 0
with open("part1_input.txt", "r") as file_input:
results = re.findall(r"mul\(\d+,\d+\)", file_input.read())
for item in results:
first_number, second_number = re.findall(r"\d+", item)
result += int(first_number) * int(second_number)
print(result)

1
day3/part1_input.txt Normal file

File diff suppressed because one or more lines are too long

28
day3/part2.py Normal file
View File

@ -0,0 +1,28 @@
import re
result = 0
with open("part2_input.txt", "r") as file_input:
raw_key_values = re.findall(r"(mul\(\d+,\d*\))|(do\(\))|(don't\(\))", file_input.read())
key_values = []
for match_tuple in raw_key_values:
temp_list = list(match_tuple)
temp_filtered_list = list(filter(None, temp_list))
key_values.append(temp_filtered_list[0])
skip = False
math_list = []
for item in key_values:
if item == "don't()":
skip = True
continue
elif item == "do()":
skip = False
continue
elif skip:
continue
math_list.append(item)
for item in math_list:
first_number, second_number = re.findall(r"\d+", item)
result += int(first_number) * int(second_number)
print(result)

1
day3/part2_input.txt Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))

View File

@ -0,0 +1 @@
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))