Adding day 3
This commit is contained in:
parent
15a9c968c8
commit
4ebe53ac4f
10
day3/part1.py
Normal file
10
day3/part1.py
Normal 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
1
day3/part1_input.txt
Normal file
File diff suppressed because one or more lines are too long
28
day3/part2.py
Normal file
28
day3/part2.py
Normal 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
1
day3/part2_input.txt
Normal file
File diff suppressed because one or more lines are too long
1
day3/test_part1_input.txt
Normal file
1
day3/test_part1_input.txt
Normal 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))
|
||||||
1
day3/test_part2_input.txt
Normal file
1
day3/test_part2_input.txt
Normal 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))
|
||||||
Loading…
Reference in New Issue
Block a user