Skip to content

Commit

Permalink
day 3 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagowfx committed Dec 3, 2024
1 parent 0c230be commit 71ed2e3
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 2024/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Advent of Code 2024 - My Solutions

![Completion Status](https://img.shields.io/badge/stars%20⭐-5/50-yellow)
![Completion Status](https://img.shields.io/badge/stars%20⭐-6/50-yellow)

The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check the places they think he was most likely to visit.

27 changes: 23 additions & 4 deletions 2024/day3/main.py
Original file line number Diff line number Diff line change
@@ -7,17 +7,36 @@ def main():
with open(sys.argv[1]) as input:
lines = input.read().splitlines()

prod = 0
prod = prod_two = 0

for memory in lines:
matches = re.findall(r'mul\(\d+,\d+\)', memory)
ops = re.findall(r'mul\(\d+,\d+\)', memory)

for match in matches:
(f1, f2) = map(int, re.findall(r'\d+', match))
for op in ops:
(f1, f2) = map(int, re.findall(r'\d+', op))
prod += f1 * f2

# part one
print(prod)

enabled = True
for memory in lines:
ops = re.findall(r"mul\(\d+,\d+\)|do\(\)|don't\(\)", memory)

for op in ops:
if "don't" in op:
enabled = False
elif "do" in op:
enabled = True
elif 'mul' in op:
(f1, f2) = map(int, re.findall(r'\d+', op))

if enabled:
prod_two += f1 * f2

# part two
print(prod_two)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions 2024/day3/output.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
178886550
87163705
2 changes: 1 addition & 1 deletion 2024/day3/sample.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))

0 comments on commit 71ed2e3

Please sign in to comment.