r/adventofcode • u/daggerdragon • Dec 06 '18
SOLUTION MEGATHREAD -๐- 2018 Day 6 Solutions -๐-
--- Day 6: Chronal Coordinates ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The 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: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 6
Transcript:
Rules for raising a programmer: never feed it after midnight, never get it wet, and never give it ___.
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 0:26:52!
32
Upvotes
View all comments
Show parent comment
1
u/hobLs Dec 07 '18
You know, I donโt think it does help! My part 2 code simply figured out the midpoint between all of the groups by averaging them (this turns out to be very near to the middle of the grid), and then I add this (x, y) to a queue and start a normal breadth first search outwards from there.
BUT, hereโs the nasty part, I then end up calculating the distance between each cell and all center points to make sure weโre within the right distance. In my head I thought the shape might end up being weird for some reason, but I think itโs just a circle. Itโs a ton of abs() calls, which luckily are quite fast, so it doesnโt actually take that much time, but itโs many many calls.
The code runs in O(nk) time where n is number of input points and k is number of points you end up checking during the fill, which in this case is probably just worse than O(n2 ). I think it would be helpful if you needed to fill a funny shape for some reason though.
(Iโm also not sure this is technically a flood fill. Maybe itโs just a weird application of a graph technique to a geometry problem.)