Copyright | (c) Eric Mertens 2022 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2022/day/11
This solution relies on the fact that there are no interactions between items, so each item can be simulated separately. When a monkey throws an item to a monkey with a larger ID that monkey will get to throw the item in the same round, but when it throws it to an earlier monkey, that item will not be thrown until the next round. Using this we can keep track of when an item would stop moving.
>>>
:{
:main + "Monkey 0:\n\ \ Starting items: 79, 98\n\ \ Operation: new = old * 19\n\ \ Test: divisible by 23\n\ \ If true: throw to monkey 2\n\ \ If false: throw to monkey 3\n\ \\n\ \Monkey 1:\n\ \ Starting items: 54, 65, 75, 74\n\ \ Operation: new = old + 6\n\ \ Test: divisible by 19\n\ \ If true: throw to monkey 2\n\ \ If false: throw to monkey 0\n\ \\n\ \Monkey 2:\n\ \ Starting items: 79, 60, 97\n\ \ Operation: new = old * old\n\ \ Test: divisible by 13\n\ \ If true: throw to monkey 1\n\ \ If false: throw to monkey 3\n\ \\n\ \Monkey 3:\n\ \ Starting items: 74\n\ \ Operation: new = old + 3\n\ \ Test: divisible by 17\n\ \ If true: throw to monkey 0\n\ \ If false: throw to monkey 1\n" :} 10605 2713310158
Documentation
type Input = [(Int, [Int], Char, Maybe Int, Int, Int, Int)] Source #
Input file contains a list of:
- Monkey ID
- Starting items
+
or*
- A literal or the
old
variable - A divisor
- The monkey ID when the divisor divides the value
- The monkey ID when the divisor does not divide the value