this post was submitted on 01 Dec 2023
18 points (100.0% liked)
NotAwfulTech
364 readers
2 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
Day 5: If You Give A Seed A Fertilizer
https://adventofcode.com/2023/day/5
Leaderboard completion time: 26m37s, so it's the toughest problem this year so far.
I liked the slight trickiness of part 2, that the naive implementation would never complete in time.
As always doing a JQ implementation:
Part 1
Some comments:
input
first to get the seeds, theninputs
to get remaining lines.Part 2
Some comments:
[1,2,3] | [ .[] | if . == 2 then . * 10 + 1 , . * 10 + 2 else . end ]
->[1, 21, 22, 3]
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 <
JQ looks like magic. So short! So clean! What's the catch?
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.
Thanks for the insight!