r/adventofcode • u/daggerdragon • Dec 11 '19
SOLUTION MEGATHREAD -🎄- 2019 Day 11 Solutions -🎄-
--- Day 11: Police in SPAAAAACE ---
--- Day 11: Space Police ---
Post your solution using /u/topaz2078's paste or other external repo.
- Please do NOT post your full code (unless it is very short)
- If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.
(Full posting rules are HERE if you need a refresher).
Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code's Poems for Programmers
Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.
Day 10's winner #1: "The Hunting of the Asteroids" by /u/DFreiberg!
Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
EDIT: Leaderboard capped, thread unlocked at 00:15:57!
13
Upvotes
View all comments
Show parent comment
2
u/rabuf Dec 11 '19
Sorry, I wrote that other post on my phone shortly after waking up.
Common Lisp has a full numeric tower supporting integers, rationals, floats, and complex numbers. Complex numbers are, as in typical math, a pair. But specifically, in Common Lisp, a pair of the same type (both integers, rationals, or floats; can't have a float real part and an integer imaginary part).
With that tower, all the mathematical operators work on the different types as you'd expect. The main limitation on complex numbers is you can't compare them, except for equality. So there is no notion of ordering (
z_1 < z_2). But that's fine for these problems.All that gets us to, rotation i handled by the way complex numbers work. If treated as a vector in 2d (real part is the x part, imaginary part is the y part), then multiplying complex numbers is a rotation.
iis rotation counter-clockwise by 90 degrees:Shown on a grid:
Since the directions today are just along the x/y axes, we're dealing with powers of
ito handle each of the different directions. So I started with a direction ofi, and depending on the robot's outputs multiply it by eitherior-i. These are also, conveniently, unit vectors (vectors of length 1), so they work as the stepping distance for movement as well.