78
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
8 of 8
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


[removed]
Restore AllHide UnarchivedIt'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?
Comment removed. Top-level comments in
Solution Megathreads are for code solutions only.Create your own individual
Helppost in /r/adventofcode.Hi. suppose that we want to check if a number is divisible by 4. 5 is not divisible as 1. in other words. if 5 is not divisible then also 1 isn't divisible. so we can check if 1 is divisible insteed of 5, and 5 is just 5-4. we can rest any divisible number and the resultant is as equal divisible as the original. what number can we substract?. the multiplication of all the divisible check numbers is always divisible by all checks. this also is the same as get de modulus