πŸ’Ύ Archived View for gerikson.com β€Ί gemlog β€Ί misc β€Ί AoC-2021.gmi captured on 2021-12-17 at 13:26:06. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-06)

➑️ Next capture (2022-01-08)

🚧 View Differences

-=-=-=-=-=-=-

The occasional geminer - an artisanal, handcrafted gemlog

↑ latest entries

Advent of Code 2021

This is a mirror of the main blog post

code listing

Advent of Code site

Day 01 - Sonar Sweep

And we're off!

I wonder if I got a bit too clever by half in this solution, as I've been looking over older solutions and can't even remember solving them. But that's how it goes I guess.

Puzzle rating: 3/5

Score: 2

Day 02 - Dive!

A "standard" Perlish solution (well, *my* kind of Perl, anyway): a dispatch table for the else/if "switch" construct, and a compact hash containing the state of the two solutions.

Puzzle rating: 3/5

Score: 2

Day 03 - Binary Diagnostic

I was honestly surprised that the canonical solution to this wasn't some esoteric bit-twiddling trick that reduces it to a one-liner.

In part 2, the naive solution is to loop through each "column" to determine which values to count so as to determine whether they are most frequent or not. I used an index for each "set" to keep track of the values already assigned to that set.

Puzzle rating: 3/5

Score: 2

Day 04 - Giant Squid

Fairly straight-forward, although part 2 threw me for a loop. I didn't find a good way to determine the exit condition.

Puzzle rating: 4/5

Score: 2

Day 05 - Hydrothermal Venture

Finally ok with my solution.

The first attempt got the job done, but was super-scruffy. I realized after I'd finished that I could treat the direction as unit vectors and work from there, so I re-wrote my solution, but only in as so far as to use the direction as a "selector" to chose which subroutine to call to "paint" the map.

After adding that to the repo, I finally remembered what I'd decided before the rewrite - to use the value of the vector in the paint routine itself.

Note that just using `atan2` blindly to determine the direction will point the Y axis incorrectly. It's probably only an issue if you're printing the results, but I found that very helpful in debugging.

If anything good can be said about this method is that I eliminated a lot of weirdness along the way. It wasn't all wasted effort.

Puzzle rating: 3/5

Score: 2

Day 06 - Lanternfish

I got off on a bad start with this puzzle, because it worked perfectly for the test input but failed for my puzzle input. I whinged about it on IRC, mentioning I had a very old fish (41 days!). Turns out that was a mispaste and fixing that gave me the correct solution.

I got the answer to the second part 40 seconds later.

Puzzle rating: 4/5, just because my solution was so smooooth

Score: 2

Day 07 - The Treachery of Whales

A quite fun one, and the first this year I managed to solve within 1hr of release. This might be TMI but I usually perform my morning ablutions and brew a pot of coffee before starting on a puzzle.

Thinking about this led me to try the average (mean) of the values as the natural solution, but that gave incorrect values. So I just checked the fuel consumption for each and every possible end point, selecting the minimum value. This went plenty fast, as did part 2 once I didn't actually step through each distance calculating fuel as I went (hint: google "Gauss sum 100").

When I had both solutions, I checked the various IRC chats and subreddits and discovered a raging debate on whether taking the median for part 1 and the average for part 2 always gave the correct result for every input. For me they did, so I just restricted by search space to the span of these values, plus a few extra integers for safety. This shaved a couple more milliseconds off the run time.

Puzzle rating: 4/5, I like grade school math

Score: 2

Day 08 - Seven Segment Search

Today was a tough one - not the problem, per se, but commitments that made it hard to me to get to a solution that I was happy with.

In the end I just went for brute-forcing every possible permutation, which is 7! or 5,040. The solution takes around 2s to run on my VPS.

Puzzle rating: 3/5, bit fiddly

Score: 2

Day 09 - Smoke Basin

This was a straight-forward problem.

I'm a bit surprised my BFS solution worked first time.

Puzzle rating: 3/5

Score: 2

Day 10 - Syntax Scoring

Not the most elegant solution but it gets the job done.

Puzzle rating: 3/5

Score: 2

Day 11 - Dumbo Octopus

Nice and easy, got 2 stars within one hour of downloading the input.

I don't think my handling of some flags (`$has_changed`, `$has_synced`) is the most elegant. I'm pretty sure I'm doing an extra scan of the entire map every step to ensure everything has settled down. But I get a result within 1s (*just*) so let's do some weekend chores instead.

I suspect tomorrow will be... more challenging.

Puzzle rating: 3/5

Score: 2

Day 13 - Transparent Origami

As usual, a breather after the weekend.

I was tearing my hair out, running spot checks on my code, before I realized I had coded my output incorrectly.

The rest of my issues was making it read the right way up...

"Best" result so far, around rank 6,500 for part 1...

Puzzle rating: 3/5

Score: 2

Day 14 - Extended Polymerization

A tough but fun problem.

Part 1 only for now.

Puzzle rating: 4/5

Score: 2

Day 15 - Chiton

I think I finally figured out <strike>A\*</strike>Dijkstra's. With the help of a lot of cribbing from previous solutions (like 2018 day 22).

I've only included part 2 because I can't be bothered bounding the box for part 1 so it doesn't choose a cheaper solution outside those limits.

Puzzle rating: 4/5

Score: 2

Day 16 - Packet Decoder

Many people went "BERR" when they saw this: Binary Encoded Register Rodeo!

I had a lot of problems with this, mostly because I managed to get the correct solution for part one a bit by accident, which didn't help solving part 2.

After a day of tearing my hair trying to pass data between recursion levels I managed to solve it.

Puzzle rating: 4/5 - tough, but fair

Score: 2

Day 17 - Trick Shot

Suspiciously easy.

This year's last weekend is coming up.

Brace yourselves.

Puzzle rating: 3/5

Score: 2

────────────────────────────────────────────

Updated on Friday, 2021-12-17

✽ Wednesday, 2021-12-01

β†’ more posts in the β€Ήmiscβ€Ί category

About this category: β€œWhat is says in the URL path”

Copyright Β© 2018 - 2021 Gustaf Erikson

Main page for this gemsite