Day 11 - Advent of Code 2022 Hints
To solve this problem, we need to simulate the game by implementing a function that takes as input the starting items for each monkey, the operation each monkey will perform, the test each monkey will use to decide where to throw the next item, and the monkeys to which each monkey will throw the item if the test is true or false.
The function should simulate the game by performing the following steps in a loop until there are no items left in any monkey’s possession:
Start with the first monkey (monkey 0). For each item the monkey is currently holding, perform the following steps:
Perform the operation on the item’s worry level to get the new worry level. Divide the new worry level by 3 and round it down to the nearest integer. Test the new worry level using the monkey’s test. If the test is true, throw the item to the monkey specified in the “If true” clause. If the test is false, throw the item to the monkey specified in the “If false” clause. Move to the next monkey and repeat the above steps until all monkeys have had a turn.
Repeat the above steps until there are no items left in any monkey’s possession.
The function should return the final items held by each monkey.
- Parsing the input data into a useful structure is complex and should be thoroughly inspected before anything else
- You could use a class to group the Monkey behaviour such as inspecting and testing an item
- The numbers we’re dealing with are going to get much larger now due to increased iteration count
- This will likely cause a basic implementation of part 1 to slow down
- We don’t actually need to deal with the original worry values
- So long as worry values satisfy the division properties given, the counts can still be calculated