r/adventofcode • u/torpetestu • Dec 28 '18
Help Day 23 - AOC creator's logic
Hi! I would be (and I assume, many others) interested in the original solution for day 23. Moreover,
every problem has a solution that completes in at most 15 seconds on ten-year-old hardware.
Please, u/topaz2078 when you'll have some free time, could you share your basic idea on part 2 with us? Thank you in advance!
15
Upvotes
29
u/topaz2078 (AoC creator) Dec 28 '18
As people have discussed, many approaches work for this puzzle, which is sort of the point. This is meant to be one of the hardest problems in the set, but only because the problem space is difficult to visualize and requires a decent amount of cleverness to find a suitably efficient solution. I actually wasn't expecting people to use things like SAT solvers, and I'm pretty surprised by the 3d/4d mapping solution, which I hadn't even considered. My solver uses an octree scan to find the best point, which only requires the ability to break cubes into smaller cubes and the ability to detect whether a cube is in range of a point, both of which can be done with very slow, naive approaches and still get an efficient result. Other users had some success with some variant of a random walk, which would get trapped within local minima for an arbitrary set of points, but will rapidly find the right region for every input the puzzle actually gives a user, and then the best point within that region can be found with a 3d sweep. I also saw users that handled each axis of the problem individually, finding the answer by using those one-dimensional density maps as a heuristic for naive region scans. Basically, there are lots of approaches, and variants of them should all work for the inputs the puzzle actually used.
2
u/llthomps Dec 30 '18
I was having so much trouble with this; trying to find libraries which would plot overlaps in 3D spaces (a subject I have zero expertise in), that I went back to the drawing board and found a working solution by reverse engineering the puzzle input, avoiding any notion that I was working on a multi-billion point grid or whatever. Because the puzzle asks for a sum of points, I created ranges for each node in a cluster (computed using Manhattan distances from each node), and was able to narrow it down to one matching answer.
So, for the sample input:
In this example, 36 is the only possible answer (which is the correct answer).
1
u/ragona_ Dec 28 '18
My solution to Day 23 Part 2 takes about 2 seconds in Python with no real optimizations. The basic idea is that I use a heap to search progressively smaller areas, rejecting areas that don't reduce to a good answer. This allows you to path through local maxima to avoid getting stuck. I'm sure that other languages could get this down to a small number of ms.
0
u/[deleted] Dec 28 '18
[deleted] — view deleted comment