this post was submitted on 02 Dec 2024
14 points (100.0% liked)

NotAwfulTech

385 readers
3 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
[–] [email protected] 3 points 3 weeks ago

Day 3 well suited to JQ

Part 2#!/usr/bin/env jq -n -R -f

reduce (
  inputs |   scan("do\\(\\)|don't\\(\\)|mul\\(\\d+,\\d+\\)")
         | [[scan("(do(n't)?)")[0]], [ scan("\\d+") | tonumber]]
) as [[$do], [$a,$b]] (
  { do: true, s: 0 };
    if $do == "do" then .do = true
  elif $do         then .do = false
  elif .do         then .s = .s + $a * $b end
) | .s