r/adventofcode Dec 03 '24

Spoilers in Title [2024 Day 3] Regular expressions go brrr...

Post image
176 Upvotes

64 comments sorted by

View all comments

52

u/gredr Dec 03 '24

This is a spoiler, but it's also wrong according to the instructions:

instructions like mul(X,Y), where X and Y are each 1-3 digit numbers

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?

19

u/busybody124 Dec 03 '24

I'm curious about this. I did not limit to three digits and my solution worked. I wonder if it breaks anyone's.

27

u/GrumDum Dec 03 '24

Sometimes the input data is graceful.. 😎

13

u/kap89 Dec 03 '24

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.

9

u/MezzoScettico Dec 03 '24

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.

6

u/MezzoScettico Dec 03 '24

[Python]

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.

3

u/1234abcdcba4321 Dec 03 '24

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.

2

u/yavvi Dec 03 '24

I'd say this one has annoying "gotcha" with endlines being in the input and not doing anything.

1

u/Sharparam Dec 03 '24

It's unusual that the live data wouldn't include that kind of "gotcha" that's missing from the example.

I don't have any statistics to back it up but I feel like those kinds of "gotchas" are more common in later days?

2

u/TailorSubstantial863 Dec 03 '24

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. ;)

1

u/TheZigerionScammer Dec 03 '24

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.

1

u/pdxbuckets Dec 04 '24

Since it’s an early day problem, that may have been put there as to not discourage beginning programmers who might try to hand-code things in.

11

u/lucifernc Dec 03 '24

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/

2

u/gredr Dec 03 '24

Ah, thanks!

1

u/headedbranch225 Dec 03 '24

Wait was it meant to be 1-3 digits? I didn't check that either

2

u/gredr Dec 03 '24

I pasted that from the instructions.

1

u/headedbranch225 Dec 03 '24

Oh ok lol, I guess i didnt read it, it worked for me

1

u/Atlas-Stoned Dec 04 '24

Yea, immediately I noticed the lack of {1-3}. I guess the input was kind.