joshbright.com

Advent of Code 2024 (Day 3)

Published on: Sunday, December 1, 2024 at 8:00 PM PST

Written by Josh Bright

Intro

For day 3, we need to find ‘instructions’ in a big jumbled block of text that look like mul(2,4), and then multiply those numbers, and add up the result.

Part 1

This puzzle took me a bit longer than I would have liked, partially due to the sample data passing, but the real data not. This leaves me with going over each line of 3000+ characters, pulling out the valid numbers and doing manual validation. Found out that the way I was parsing out those strings wasn’t very good in cases where we had something like, mul(3,select5), and I would pull out mul(3,5) from it. After finding the problem, it was easy to fix the parser and I was able to complete it. Unfortunately I was pretty busy though and didn’t get this fixed until a couple days had gone by. Ah well, making progress!

Part 2

For part 2, pretty similar situation, except now when we encounter a do() or don't(), it toggles the action of multiplying the found result on and off. I had this fixed pretty quickly, except for a small issue that wasn’t really explained in the puzzle text, where the state of when we are and not multiplying numbers is kept between each line of input, where I was resetting it. That last quick fix got me the right answer and on to day 4!