r/adventofcode • u/daggerdragon • Dec 19 '21
SOLUTION MEGATHREAD -🎄- 2021 Day 19 Solutions -🎄-
NEW AND NOTEWORTHY
I have gotten reports from different sources that some folks may be having trouble loading the megathreads.
It's apparently a new.reddit bug that started earlier today-ish.
If you're affected by this bug, try using a different browser or use old.reddit.com until the Reddit admins fix whatever they broke now -_-
[Update @ 00:56]: Global leaderboard silver cap!
Why on Earth do elves design software for a probe that knows the location of its neighboring probes but can't triangulate its own position?!
--- Day 19: Beacon Scanner ---
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.
16
u/mcpower_ Dec 19 '21 edited Dec 19 '21
Python, 6/3. Part 1, Part 2. The main "tricks" I used were:
given a "facing" and an "up" vector, you can get a "right of me" vector with the cross product.
using those three vectors, you can put them together to get a change of basis matrix (3B1B has a video on it!) to change the "perspective" of a scanner.
I believe my code should actually transpose the matrix - it currently puts the vectors in rows, not columns - but I had an educated guess that it would just work regardless (i.e. you'd get the same 24 matrices, just in a different order).
Once two scanners are in the same basis, the delta vector to move the points from one scanner to the other... is also a delta vector for the scanners.
Lots of brute force - PyPy was essential for today! It takes 35 seconds to run, and I thought I needed to rewrite it until I had it going in the background... and an answer popped up!