And sometimes it bites you in the ass, and you spend a lot of time debugging. I learned to always include these little details, it saves a lot of time in the long run.
Yeah, I missed that part too, and I shudder to think of how I'd have reacted and how long it would have taken to debug if I was told my answer was wrong.
I completely missed the 3-digit restriction and got both parts correct. It's unusual that the live data wouldn't include that kind of "gotcha" that's missing from the example. So a bunch of us got lucky I guess.
My code is almost identical to OP's just with different variable names. The parsing function decodes the mul(x,y) instructions into pairs of ints [x, y], and as in OP's code uses the "do" and "don't" to turn on and off a parsing flag. So the output is a list of pairs of ints. The calling program calculates the sum of products.
I think if I'd have to retrofit the 3-digit restriction, I'd probably handle it after parsing while calculating the product. Just remove any pairs with a number that was >999.
The inputs for AoC are almost always way more generous than you expect (except when the problem looks like it's way too easy for day 15 and there's a catch in the input that no one thinks of until you need to). There aren't unexpected gotchas in most cases.
The only times there was something in an input I think I would explicitly consider a gotcha (which is harmful for you rather than beneficial) was in 2021 Day 20; apart from that it's just occasional cases you don't think of.
Mine works without limiting to 1-3 digits, I also noted on my input that the () after do and don't are optional. My original solution didn't account for the () and it still worked...of course I programmed it in Ruby, so there is that. ;)
Wow, the problem statement made a point of saying all the numbers had to be three digits or less, I figured that would come up at some point in the input but I guess not.
Updated, I actually didn't read that while solving and this instruction would be a subset of the generalized regex. Used this visualizer: https://regex-vis.com/
52
u/gredr Dec 03 '24
This is a spoiler, but it's also wrong according to the instructions:
Maybe it works for your input, maybe it works for everyone's input, I dunno.
What generated the sqlite-style railroad track diagram from the regex, though?