Advent 2024 Day 03
By EricMesa
- 4 minutes read - 792 wordsTime once again to review my Advent of Code solutions! Also the latest die or dice from the Dice Envy Advent Calendar; scroll below the AoC code to see today’s die.
Advent of Code
As the years have piled on, Eric Wasl has thrown in references to past years’ problems. However, as of day 3 we now have 2 references (perhaps that’s what the historian story line is about). Day 02 had you visit the location of 2015 Day 19 and today visited the location of 2020 Day 2 (my first year doing Advent of Code!) The only thing I’m slightly worried about is if this signals that this year will be a grand finale for the annual event.
Taking a look at this problem, especially because spaces make the code invalid, it seems a regex would be relatively simple. I went to https://regex101.com/ to build up my regex before I started coding. (https://regex101.com/r/QuSeil/1) Learned about using {n,m} to control how many times something repeat by searching in the bottom right. According to my test, the complex string that Eric provides:
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
Should be properly captured by the regex:
(mul\(\d{1,3},\d{1,3}\))
Hopefully that takes care of any edge cases for part 1. For part 2 I accidentally was spoiled by seeing https://www.reddit.com/r/adventofcode/comments/1h5psat/i_just_realized_every_dont_starts_with_a_do/ on reddit when the main page loaded up. Not sure how it fits in without having yet seen part 2, but it will be helpful.
For part 2 I wasn’t sure how to do the regex to make sure the “dos” and “don’ts” were in order. But I decided to first try and see what would happen if I just searched it all together. I couldn’t get that to work on regex101, so I thought about maybe doing a split on dos and don’ts. That didn’t work naively. I had a feeling I needed to go recursive. I’m not good at recursion. One other solution that might work (but I’m not sure exactly how to do it) would be to chew things up one character at a time. I decided to check reddit for a hint. Although someone did do the chewing up I was thinking of, someone on there mentioned that a split should work. So I decided to take a closer look. In the end, I started looking at implementing a solution that would look at the indexes for “dos” and “don’ts”, but ran out of time in the day before I could implement the solution. Usually I don’t start having failures so early, but this is turning out to be a harder year.
Here was my solution by the time I finished up the day:
|
|
Dice Envy Dice
Today’s die seems to be a return to the day 1’s theme, it’s another Elsa-blue die. This time it’s a d6:


I’m not sure how I feel about this bouncing back and forth, but I’m very curious to see what we get tomorrow! Will it be a return to the sparkly dice? Another Elsa-blue? Something completely different?