r/adventofcode • • Dec 23 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 23 Solutions -🎄-

--- Day 23: Experimental Emergency Teleportation ---


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!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 23

Transcript:

It's dangerous to go alone! Take this: ___


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 01:40:41!

21 Upvotes

205 comments sorted by

View all comments

Show parent comment

2

u/dashed Dec 24 '18

Why is the part 2 solution not considered correct?

3

u/rabuf Dec 24 '18 edited Dec 24 '18

If the bots aren't in the same direction from the origin you could be counting incorrectly. Consider (linear case):

<----------+---------->
   {==o==}   {==o==}
               {==o==}

This will count 2 bots both at distance 2 from the origin and consider that the best option. However the real best is 4 away.

As it happens this method works for mine, and probably many other's, because the nearest point is likely to be on the surface of one of the bot octahedrons and the nearest point on that is going to be (bot distance) - (range) from the origin. So it is checking only the correct potential distances, and since the bots themselves are heavily overlapping it happens to work out.

Which also leads to another solution which is to compute the actual closest point for each bot to the origin and check all of those.