77
SOLUTION MEGATHREAD-🎄- 2022 Day 11 Solutions -🎄-(self.adventofcode)
submitted 3 years, 1 month ago* (edited 17 minutes after) by daggerdragon to /r/adventofcode (134.8k)
WIKI NEWS
- The FAQ section of the wiki on [Code Formatting](https://www.reddit.com/r/adventofco...
since 3 years, 1 month ago
3 of 3
Tip Reveddit Real-Time can notify you when your content is removed.
your account history
Tip Check if your account has any removed comments.
view my removed comments you are viewing a single comment's thread.
view all comments


It's due to these properties of modulo arithmetic listed here: https://en.wikipedia.org/wiki/Modular_arithmetic#Properties
For all the operations we care about in this problem, op(a) == op(b) (mod n) if a == b (mod n). So as long as we choose an n large enough so that the divisibility check for each monkey can still be performed, we can keep taking the worry levels (mod n) to prevent them from growing too large.
Suppose you only have two monkeys. One has a test of dividing by 13. The other has a test of dividing by 7.
Now suppose you have an ENORMOUS worry number that's slowing down your computer, like 95.
Applying the test for the first monkey gives you the remainder 4: 95 % 13 = 4 For the second monkey it's also 4: 95 % 7 = 4 This suggests 91 is an important number, and 91 = 7 * 13!
So, you can reduce your enormous worry number on either monkey by keeping the remainder after dividing by 91.
For all eight monkeys in the puzzle, you'll see they all have prime divisors, so instead of just 7 * 13, you can reduce your enormous worry numbers in Part 2 by keeping the remainder after dividing by: monkey[0].test * monkey[1].test * monkey[2].test ... etc.
Hope that helps?