r/adventofcode • • 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^ยค?

Spoiler


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

199 comments sorted by

View all comments

Show parent comment

2

u/gtllama Dec 13 '17

I recognized the similarity to the CRT, but I don't see how you can apply the CRT to this problem. It's kind of the opposite. The CRT says, given these residues for these numbers, here is the smallest n that has those residues when you divide by those numbers. What we want in this problem is to find the smallest n that doesn't produce any of the given residues.

2

u/vash3r Dec 13 '17 edited Dec 13 '17

It's not the CRT, since there are many possible residues, but the algorithm is basically the same. In practice, it looks like the input data often eliminates large ranges: for instance in my input had only one possible residue modulo 6, 10, 14, 22, and 26, and for these the application of the CRT is relatively obvious and will give one solution modulo 30030, for which simply guessing multiples is sufficiently fast.

Also see /u/p_tseng's top-level comment.