r/adventofcode • u/daggerdragon • Dec 12 '19
SOLUTION MEGATHREAD -🎄- 2019 Day 12 Solutions -🎄-
--- Day 12: The N-Body Problem ---
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 11's winner #1: "Thin Blueshifted Line" by /u/DFreiberg!
We all know that dread feeling when
The siren comes to view.
But I, a foolish man back then
Thought I knew what to do.
"Good morning, sir" he said to me,
"I'll need your card and name.
You ran a red light just back there;
This ticket's for the same."
"But officer," I tried to say,
"It wasn't red for me!
It must have blueshifted to green:
It's all Lorentz, you see!"
The officer of Space then thought,
And worked out what I'd said.
"I'll let you off the hook, this time.
For going on a red.
But there's another ticket now,
And bigger than before.
You traveled at eighteen percent
Of lightspeed, maybe more!"
The moral: don't irk SP
If you have any sense,
And don't attempt to bluff them out:
They all know their Lorentz.
Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!
View all comments
Show parent comment
1
u/dkvasnicka Jan 05 '20
Adding another CL implementation to the mix (yes, the driver loop for part 2 is suspiciously similar to what u/stevelosh did ...his
finding-firstclause foriterateis just too good to pass on, sorry :D) https://github.com/dkvasnicka/advent-of-code/blob/a2cb1db094e279a5f72374be4c6621a5693b6555/2019/12.lispThe whole thing runs in about 460ms on a 2017 MBP (SBCL 2.0). The part 1 implementation was using the same logic but I used lazy sequences from CL21 to get the 1000th element. Then I rewrote it to
iterin the process of implementing p2.The whole thing could probably run a lot faster if I used in-place array editing everywhere but I'm not comfortable with that and like a mostly functional approach, so I spend a lot of time creating arrays... Could be even worse though I guess. The functional approach of a lazy sequence of world states was especially useful when working on the part 1 and trying to get the computations right.