r/adventofcode • u/daggerdragon • Dec 13 '17
SOLUTION MEGATHREAD -๐- 2017 Day 13 Solutions -๐-
--- Day 13: Packet Scanners ---
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.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hints^ยค?
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!
16
Upvotes
View all comments
Show parent comment
7
u/sim642 Dec 13 '17
Took me a while to think through how you're calculating this, especially not being familiar with Ruby syntax. Here's what I managed deduce:
depth + start โข 0 (mod 2*(range-1)), wheredepthandrangeare given for every scanner andstartis the variable we're looking for. Simply put:start โข -depth (mod period).I have to admit, it is pretty clever but from a mathematical point of view, not too general. The speedup only comes in the case where there are periods that forbid all but one value, hopefully multiple such to get a real big congruence at the end. I wonder if this is the case for the AoC inputs because I'm sure in general one could construct a set of depths and ranges that don't do that and maybe always leave two possible values left, etc. The optimization doesn't help in such case as is but I suppose it could be extended to still be smart enough to only consider such two cases separately and continue the reduction recursively or something. This however still sounds like it can be exponential in general if all periods leave multiple possible remainders.