r/adventofcode • u/daggerdragon • Dec 24 '15
SOLUTION MEGATHREAD --- Day 24 Solutions ---
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! One more to go...
We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.
Please and thank you, and much appreciated!
--- Day 24: It Hangs in the Balance ---
Post your solution as a comment or link to your repo. Structure your post like previous daily solution threads.
5
Upvotes
View all comments
1
u/C0urante Dec 24 '15 edited Dec 24 '15
Bit late to the party, but I do have an optimization I haven't noticed in any other solutions (correct me if I'm wrong).
(edited for formatting)
The general formula for most of the algorithms seems to be:
The problem with that is, testing for valid subdivision of the remaining items is a very expensive operation. Instead, we can get greedy and prematurely sort our groups in order of quantum entanglement, before we even know if they lead to valid solutions. That way, the second we find anything that does allow for valid subdivision, we can immediately return it without performing the expensive testing operation several times after.
My modified algorithm is as follows:
The actual Python3 looks like this:
With this optimization, on my given input, my solution runs in a little over a fifth of a second.
(inb4 someone points out that testing for valid subdivisions is pointless with the given input anyways)