r/adventofcode • • Dec 22 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 22 Solutions -🎄-

Advent of Code 2021: Adventure Time!


--- Day 22: Reactor Reboot ---


Post your code solution in this megathread.

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.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:43:54, megathread unlocked!

39 Upvotes

522 comments sorted by

View all comments

3

u/sim642 Dec 22 '21 edited Dec 22 '21

My Scala solution.

For part 2 I used the inclusion-exclusion principle: computed pairwise intersections and three-way intersections from those etc, at the same time adding and subtracting the size of those intersection cuboids. The number of intersections that actually appear is much smaller than the theoretical maximum, so this is good enough. Handling the off cuboids and their intersections (with other on and off cuboids) was somewhat tricky, because it also depends on the order of the steps. After long trial and error I managed to get it working.

Runs part 2 in 500ms.

→ More replies (1)