Skip to content

Commit 01a798f

Browse files
committed
Add Day 3
1 parent 5bec5e7 commit 01a798f

File tree

5 files changed

+165
-1
lines changed

5 files changed

+165
-1
lines changed

day-3/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Day 3: Mull It Over
2+
3+
<br>
4+
5+
## Part 1
6+
7+
"Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse,
8+
though," says the mildly flustered shopkeeper at the [North Pole Toboggan Rental Shop](https://adventofcode.com/2020/day/2). The Historians
9+
head out to take a look.
10+
11+
The shopkeeper turns to you. "Any chance you can see why our computers are having issues again?"
12+
13+
The computer appears to be trying to run a program, but its memory (your puzzle input) is **corrupted**. All of the instructions have been
14+
jumbled up!
15+
16+
It seems like the goal of the program is just to **multiply some numbers**. It does that with instructions like `mul(X,Y)`, where `X` and
17+
`Y` are each 1-3 digit numbers. For instance, `mul(44,46)` multiplies `44` by `46` to get a result of `2024`. Similarly, `mul(123,4)` would
18+
multiply `123` by `4`.
19+
20+
However, because the program's memory has been corrupted, there are also many invalid characters that should be **ignored**, even if they
21+
look like part of a `mul` instruction. Sequences like `mul(4*`, `mul(6,9!`, `?(12,34)`, or `mul ( 2 , 4 )` do nothing.
22+
23+
For example, consider the following section of corrupted memory:
24+
25+
`xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))`
26+
27+
Only the four highlighted sections are real `mul` instructions. Adding up the result of each instruction produces `161`
28+
`(2*4 + 5*5 + 11*8 + 8*5)`.
29+
30+
Scan the corrupted memory for uncorrupted mul instructions. **What do you get if you add up all of the results of the multiplications?**
31+
32+
<br>
33+
34+
## Part 2
35+
36+
As you scan through the corrupted memory, you notice that some of the conditional statements are also still intact. If you handle some of
37+
the uncorrupted conditional statements in the program, you might be able to get an even more accurate result.
38+
39+
There are two new instructions you'll need to handle:
40+
41+
- The `do()` instruction **enables** future mul instructions.
42+
- The `don't()` instruction **disables** future mul instructions.
43+
44+
Only the **most recent** `do()` or `don't()` instruction applies. At the beginning of the program, `mul` instructions are **enabled**.
45+
46+
For example:
47+
48+
`xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))`
49+
50+
This corrupted memory is similar to the example from before, but this time the `mul(5,5)` and `mul(11,8)` instructions are **disabled**
51+
because there is a `don't()` instruction before them. The other `mul` instructions function normally, including the one at the end that gets
52+
re-**enabled** by a `do()` instruction.
53+
54+
This time, the sum of the results is `48` `(2*4 + 8*5)`.
55+
56+
Handle the new instructions; **what do you get if you add up all of the results of just the enabled multiplications?**

0 commit comments

Comments
 (0)