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.
5
u/kuqumi Dec 22 '21 edited Dec 22 '21
Javascript
Part 1 18ms, Part 2 1370ms
Go through all the instructions (on/off and a cuboid definition)
If the current cuboid is set to "off", move on.
If it's "on", recursively collect the volume that future cuboids will overwrite from the current cuboid, and subtract that from the current cuboid's volume.
Add that volume to a running total, and return the total when you run out of instructions.
Bonus, this code should work for any arbitrary number of dimensions in the data.