9
votes
Day 11: Monkey in the Middle
Today's problem description: https://adventofcode.com/2022/day/11
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
Part 1, in Python-ish
Python code generated from the above
Part 2, in Python-ish
Python code generated from the above
We just can't catch a break, huh.
This had quite a few rules, and some worrying moments. But it was fun and never got too overwhelming as everything is pretty tidy despite all the monkey business.
Part 1
Part 2
Data Structures
Each monkey is a struct with 2 mutable fields.
The struct stores:
These monkeys are held in a vector.
op and test are functions take an item value (before or after inspection)
Part 1
Part 2
So you get the refactored code, which makes part 2 look very much like part 1 :) - `values` is the built-in identity function.Rust
Rust
Python