Skip Navigation

帖子
5
评论
239
加入于
2 yr. ago

  • A nice workaround to jq single threadedness, since this is maq reduce and safe to parallelize. 17m10s -> 20s !!! ::: spoiler Spoiler link to commit. https://github.com/zogwarg/advent-of-code/commit/fef153411fe0bfe0e7d5f2d07da80bcaa18c952c :::

    Not really spoilery details: Revolves around spawing mutiple jq instances and filtering the inputs bassed on a modulo of number of instances:

     
        
      # Option to run in parallel using xargs
      # Eg: ( seq 0 9 | \
      #        xargs -P 10 -n 1 ./2023/jq/12-b.jq input.txt --argjson s 10 --argjson i \
      #      ) | jq -s add
      # Execution time 17m10s -> 20s
      if $ARGS.named.s and $ARGS.named.i then #
        [inputs] | to_entries[] | select(.key % $ARGS.named.s == $ARGS.named.i) | .value / " "
      else
        inputs / " "
      end
    
      

    I use JQ at work, and never really needed this, i guess this trick is nice to have under the belt just in case.

  • Day 12: Hot springs

    https://adventofcode.com/2023/day/12

    • Leaderboard completion time: 22:57
    • Personal completion time: ahahahahahahaha (at least i had fun)

    Where a curse the fact I decided to use JQ and not a "real" programming language.

  • Ah! Thanks for making my notice the GCM -> GCD typo. I'm not gunning for the leaderboards myself, it's pretty hopeless ^^. Yes i am assuming based off of experience and utility tools.

    I myself have tools to automatically get the inputs, and submit outputs, but that's more because it pleases me than to actually be fast: https://github.com/zogwarg/advent-of-code/blob/main/functions.sh

    (Also completely pointlessly have a functions to extract the session cookie from chrome storage from the CLI, despite being long-lived, and therefore much simpler to simply copy-paste from debugger window)

  • Cleaned up version of code used to solve part 2 in jq.

  • The main catch is it would often be faster to use a "real" programming langage ^^, both in writing the code, and in execution time for some loop heavy examples: equivalent code that completes say in 1 second in python, completing in 1 minute in jq. Also missing a way to call native libraries, to do stuff like say "md5" (relevant) in past years advents-of-code.

    That being said i like the general "pipe", map-reduce feel of the language. Like bash one-liners It can make for very terse implementations. I like to add comments, and indentation to make it readable though.

  • I liked the slight trickiness of part 2, that the naive implementation would never complete in time.

    As always doing a JQ implementation:

    Replaced less-than (and greater-than for symmetry) symbols with full-width version, since lemmy apparently doesn't handle them well within a code block: replacing less than with lt;

  • Back to a more straightfoward day, do they make them harder on the weekends?

    Day 4 Scratchcards

  • Have been mostly using jq for fun.

    Day 1

    First part was easy, and very suited to jq

    Second part was harder than expected, i had to resort to regex.

    Day 2

    Not too much trickery in this example.

    Satisifyingly straightfoward edit form part one.

    Day 3

    Took More time than i expected, glad i had the idea early to search by the indices of the symbols and not the digits. Not super well suited to jq, unless I'm missing a better solution.

    Not too far of an edit from part one.

  • One (simpler) explanation is that proving an absence of something is almost impossible, and that attempting too hard would make them look a heck of a lot guilty.

    There is a good reason why the burden of evidence is “innocent until proven guilty”, and yes this extends to the (in your eyes) untrustworthy.

    Prove to me you never stole candy from a store as a child (or if you did, replace that accusation with any item of higher value until you hit something you did not steal)

  • One of the more disturbing things that happened at work when using MS Word, was the automatic addition of alt-text images. I didn't ask for that, I didn't click any "Please send my images to the cloud, possibly leaking sensitve material, so inference can be run there, to add potentially unhelpful descriptions"

    Is document editing really a task that benefits from AI?

    An example of unhelpfulness:

    I'm torn between at almost praising meek half-assed attempt at accessibility, and shrieking to the heavens about this unweclome shoe-horned addition.

  • Either way it's a circus of incompetence.

  • Something something Poe's law, something something. Honestly some of the shit i've read should have been satire, but noooooo.

  • Absolutely this, shuf would easily come up in a normal google search (even in googles deteriorated relevancy).

    For fun, "two" lines of bash + jq can easily achieve the result even without shuf (yes I know this is pointlessly stupid)

     bash
        
    cat /usr/share/dict/words | jq -R > words.json
    cat /dev/urandom | od -A n -D | jq -r -n '
      import "words" as $w;
      ($w | length) as $l |
      label $out | foreach ( inputs * $l / 4294967295 | floor ) as $r (
        {i:0,a:[]} ;
        .i = (if .a[$r] then .i  else .i + 1 end) | .a[$r] = true ;
        if .i > 100 then break $out else $w[$r] end
      )
    '
    
      

    Incidentally this is code that ChatGPT would be utterly incapable of producing, even as toy example but niche use of jq.

  • Almost always sneerious Yud.

  • Ah, but each additional sentence strikes home the point of absurd over-abundance!

    Quite poetically, the sin of verbosity is commited to create the illusion of considered thought and intelligence, in the case of hpmor literally by stacking books.

    Amusingly him describing his attempt as "striking words out" rather than "rewording" or "distilling", i think illustrates his lack of editing ability.