Re:Advent of Code 2023 is nigh
by hypersoar on Friday December 01, 2023 @01:12PM
(#38490102)
I heard the question was difficult before solving it, and then I was surprised when I didn't hit any speed bumps. The overlapping case didn't even occur to me. It turns out I stumbled upon a simple solution: use two regexes. One to match the first digit, and one to match the last. Then the overlapping is a total non-issue.
[ Parent
| on HN ]
If the whole numeric part of the string was something like "eightwo", I think that solution would fail.
It would only fail if you replace “eight” by “8”, but if you don’t replace anything then it will work fine
As a matter of fact, it does not.
Re:Advent of Code 2023 is nigh
by stefandesu on Saturday December 02, 2023 @03:05AM
(#38496878)
Yeah, that's what I did for part 2 and there were no issues. I did try to solve it with a single regex at first, but for some reason I wasn't able to figure out the right combination of lazy/greedy matches to make it work (so I didn't even get far enough to discover the overlap issue).