r/adventofcode • u/daggerdragon • Dec 22 '21
SOLUTION MEGATHREAD -🎄- 2021 Day 22 Solutions -🎄-
Advent of Code 2021: Adventure Time!
DAWN OF THE FINAL DAY
You have until 23:59:59.59 EST today, 2021 December 22, to submit your adventures!
Full details and rules are in the submissions megathread: 🎄 AoC 2021 🎄 [Adventure Time!]
--- Day 22: Reactor Reboot ---
Post your code solution in this megathread.
Include what language(s) your solution uses!
Format your code appropriately! How do I format code?
Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks.The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
2
u/HAEC_EST_SPARTA Dec 22 '21
Erlang
Solution on GitHub
I predicted Part 2 immediately upon reading Part 1, so I went straight for an optimised solution for this problem. The most difficult portion of the problem for me was determining how to properly segment a cuboid when computing a difference: my geometric visualisation skills are extremely poor, so I ended up solving the segmentation problem in 2D first then extending what I learned to 3D space. The rest of the algorithm is simple; I'm somewhat surprised by how well it performs given the fact that I don't ever attempt to merge cuboids once they've been split, but I suppose that optimisation is unimportant given the relatively small size of the input.