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
 

copy pasting the rules from last year's thread:

Rules: no spoilers.

The other rules are made up aswe go along.

Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.

you are viewing a single comment's thread
view the rest of the comments
[–] swlabr@awful.systems 3 points 1 day ago* (last edited 1 day ago)

For 3: I made dart one-liners for both. Pasting the juicy parts.

3:1RegExp(r"mul\((\d*),(\d*)\)").allMatches(input).fold( 0, (p, e) => p + e.groups([1, 2]).fold(1, (p, f) => p * int.parse(f!))));

3:2My 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