8
this post was submitted on 02 Dec 2024
8 points (100.0% liked)
NotAwfulTech
6 readers
5 users here now
a community for posting cool tech news you don’t want to sneer at
non-awfulness of tech is not required or else we wouldn’t have any posts
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
For 3: I made dart one-liners for both. Pasting the juicy parts.
3:1
RegExp(r"mul\((\d*),(\d*)\)").allMatches(input).fold( 0, (p, e) => p + e.groups([1, 2]).fold(1, (p, f) => p * int.parse(f!))));
3:2
My original solution found do, don't and mul entries, then stepped through them to get the solve. I decided to try regex my way through it. What I realised was that you want to ignore strings starting with don't() and ending at the first do(). Some amount of trial and error later, I figured out the (ecma*) regex to do it, which I am proud of:RegExp(r"(?:don\'t\(\)(?:.(?( 0, (p, e) => p + (e.group(0)![0] != 'd' ? e.groups([1, 2]).fold(1, (p, f) => p * int.parse(f!)) : 0))
*ecma balls