top | item 38490102

(no title)

hypersoar | 2 years ago

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.

discuss

order

stefandesu|2 years ago

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

abound|2 years ago

If the whole numeric part of the string was something like "eightwo", I think that solution would fail.

pprotas|2 years ago

It would only fail if you replace “eight” by “8”, but if you don’t replace anything then it will work fine