Advent of Code Day 3 revisited

So, originally I did this the old school style, parsing the input string character by character, managing the state of processing while discovering the elements from the input string.

Tonight I reimplemented part 1 using #Swift RegexBuilder. I’ve never been comfortable in using regular expressions (regex) but wanted to give a try.

Swift RegexBuilder code snippet showing how to pick up the mul instructions with parameters from the day's puzzle input.
Snippet of RegexBuilder code showing how to specify what elements to pick from the input string.

Got it working nicely after some hiccups, as usual – wondered why the sum of mul operations was smaller than expected, and it was because I had Repeat(1...2) instead of Repeat(1...3) in the code. Didn’t notice that some mul parameters were three numbers, since in puzzle examples there were only two numbers. So the regex was only picking first two numbers at most from the input :facepalm:

Learned something new. Maybe regexes are not so terrifying things after all…

An illustration depicting a muscular figure reminiscent of a Greek warrior, labeled "PROGRAMMERS," with an arrow lodged in its leg labeled "REGEX." The style is simplistic and humorous, emphasizing the struggles programmers face with regular expressions.