r/adventofcode • u/jonathan_paulson • Dec 25 '18
Tutorial Day 23 Part 2 - Adversarial input for recursive partitioning solutions
The most common solution idea I've seen proposed for this problem is recursive partitioning. The idea: keep a priority queue of spaces left to explore, ordered by (biggest # of bots intersecting the space, smallest distance to origin, smallest size). Start with the entire space, and recursively partition it into 8 cubes or 6 spheres or something, keeping track of how many bots intersect each recursive space. Stop once you see a space of size 1. This is guaranteed to be the right answer, since all other candidates have worse tiebreakers.
What is the worst-case performance of this idea? The main variability is how much space it has to explore. If it can quickly narrow in on the most promising area, it may not have to explore much at all. But if there are a lot of false positives that look potentially good but aren't really, it will be slow.
How could we construct input with a lot of false positives? We need a lot of near collisions in our nanobots, so that at coarse resolutions, a lot of things will look connected, but as we zoom in, they will turn out not to be.
Let's make a grid of nanobots that barely don't touch on each face. Then the real answer will be 1. But each pair of faces will appear to touch on any coarser grid scale. So any recursive partitioning solution will have to scan over the whole area of each face with its smallest-but-one grid size. Since each face has area proportional to radius2 (which can be enormous), this will make such solutions run slowly. Here is some input which implements this idea: https://pastebin.com/9eJQN836
If you have a recursive-partitioning solution that runs quickly on this input, let me know.
View all comments
Show parent comment
3
u/p_tseng Dec 27 '18 edited Dec 27 '18
I want to add to the explanation that askalski already has given (https://www.reddit.com/r/adventofcode/comments/a9co1u/day_23_part_2_adversarial_input_for_recursive/ecnvkn6/) by saying this: The solutions that partition the space into 3d cubes may potentially be required to partition the space at any possible point along each axis, because the bots' ranges are octahedra.
On the other hand, this new solution that partitions the 4d space is guaranteed that the number of intersections can only change where an interval begins and ends, because these intervals are exactly the inequalities that describe when a point will fall into the octahedron. Thus, along the x+y+z axis, we are only ever required to partition at points x+y+z+r or x+y+z-r where (x, y, z, r) describe one bot. And the same goes for all other axes. Now that we are only required to partition at 2000 (or in askalski's case 2001) points per axis as opposed to a few million, we get to do much less work, despite the fact that we have to partition along an extra axis.
If you can't wait for askalski's code, I offer you that I have taken askalski's description and implemented it in https://github.com/petertseng/adventofcode-rb-2018/blob/master/23_emergency_teleportation.rb . Since I'm using an interpreted language I can't touch the same speeds, but it does complete typical Advent of Code inputs in 0.2 seconds and this adversarial input in about 41 seconds.
I also can't wait to see /u/askalski's work, to see all the additional tricks I am sure I have missed.