advent2022

Advent of Code 2022 Solutions
git clone git://bsandro.tech/advent2022
Log | Files | Refs | README | LICENSE

task.txt (12565B)


      1 --- Day 11: Monkey in the Middle ---
      2 
      3 As you finally start making your way upriver, you realize your pack is much lighter than you remember. Just then, one of the items from your pack goes flying overhead. Monkeys are playing Keep Away with your missing things!
      4 
      5 To get your stuff back, you need to be able to predict where the monkeys will throw your items. After some careful observation, you realize the monkeys operate based on how worried you are about each item.
      6 
      7 You take some notes (your puzzle input) on the items each monkey currently has, how worried you are about those items, and how the monkey makes decisions based on your worry level. For example:
      8 
      9 Monkey 0:
     10   Starting items: 79, 98
     11   Operation: new = old * 19
     12   Test: divisible by 23
     13     If true: throw to monkey 2
     14     If false: throw to monkey 3
     15 
     16 Monkey 1:
     17   Starting items: 54, 65, 75, 74
     18   Operation: new = old + 6
     19   Test: divisible by 19
     20     If true: throw to monkey 2
     21     If false: throw to monkey 0
     22 
     23 Monkey 2:
     24   Starting items: 79, 60, 97
     25   Operation: new = old * old
     26   Test: divisible by 13
     27     If true: throw to monkey 1
     28     If false: throw to monkey 3
     29 
     30 Monkey 3:
     31   Starting items: 74
     32   Operation: new = old + 3
     33   Test: divisible by 17
     34     If true: throw to monkey 0
     35     If false: throw to monkey 1
     36 
     37 Each monkey has several attributes:
     38 
     39     Starting items lists your worry level for each item the monkey is currently holding in the order they will be inspected.
     40     Operation shows how your worry level changes as that monkey inspects an item. (An operation like new = old * 5 means that your worry level after the monkey inspected the item is five times whatever your worry level was before inspection.)
     41     Test shows how the monkey uses your worry level to decide where to throw an item next.
     42         If true shows what happens with an item if the Test was true.
     43         If false shows what happens with an item if the Test was false.
     44 
     45 After each monkey inspects an item but before it tests your worry level, your relief that the monkey's inspection didn't damage the item causes your worry level to be divided by three and rounded down to the nearest integer.
     46 
     47 The monkeys take turns inspecting and throwing items. On a single monkey's turn, it inspects and throws all of the items it is holding one at a time and in the order listed. Monkey 0 goes first, then monkey 1, and so on until each monkey has had one turn. The process of each monkey taking a single turn is called a round.
     48 
     49 When a monkey throws an item to another monkey, the item goes on the end of the recipient monkey's list. A monkey that starts a round with no items could end up inspecting and throwing many items by the time its turn comes around. If a monkey is holding no items at the start of its turn, its turn ends.
     50 
     51 In the above example, the first round proceeds as follows:
     52 
     53 Monkey 0:
     54   Monkey inspects an item with a worry level of 79.
     55     Worry level is multiplied by 19 to 1501.
     56     Monkey gets bored with item. Worry level is divided by 3 to 500.
     57     Current worry level is not divisible by 23.
     58     Item with worry level 500 is thrown to monkey 3.
     59   Monkey inspects an item with a worry level of 98.
     60     Worry level is multiplied by 19 to 1862.
     61     Monkey gets bored with item. Worry level is divided by 3 to 620.
     62     Current worry level is not divisible by 23.
     63     Item with worry level 620 is thrown to monkey 3.
     64 Monkey 1:
     65   Monkey inspects an item with a worry level of 54.
     66     Worry level increases by 6 to 60.
     67     Monkey gets bored with item. Worry level is divided by 3 to 20.
     68     Current worry level is not divisible by 19.
     69     Item with worry level 20 is thrown to monkey 0.
     70   Monkey inspects an item with a worry level of 65.
     71     Worry level increases by 6 to 71.
     72     Monkey gets bored with item. Worry level is divided by 3 to 23.
     73     Current worry level is not divisible by 19.
     74     Item with worry level 23 is thrown to monkey 0.
     75   Monkey inspects an item with a worry level of 75.
     76     Worry level increases by 6 to 81.
     77     Monkey gets bored with item. Worry level is divided by 3 to 27.
     78     Current worry level is not divisible by 19.
     79     Item with worry level 27 is thrown to monkey 0.
     80   Monkey inspects an item with a worry level of 74.
     81     Worry level increases by 6 to 80.
     82     Monkey gets bored with item. Worry level is divided by 3 to 26.
     83     Current worry level is not divisible by 19.
     84     Item with worry level 26 is thrown to monkey 0.
     85 Monkey 2:
     86   Monkey inspects an item with a worry level of 79.
     87     Worry level is multiplied by itself to 6241.
     88     Monkey gets bored with item. Worry level is divided by 3 to 2080.
     89     Current worry level is divisible by 13.
     90     Item with worry level 2080 is thrown to monkey 1.
     91   Monkey inspects an item with a worry level of 60.
     92     Worry level is multiplied by itself to 3600.
     93     Monkey gets bored with item. Worry level is divided by 3 to 1200.
     94     Current worry level is not divisible by 13.
     95     Item with worry level 1200 is thrown to monkey 3.
     96   Monkey inspects an item with a worry level of 97.
     97     Worry level is multiplied by itself to 9409.
     98     Monkey gets bored with item. Worry level is divided by 3 to 3136.
     99     Current worry level is not divisible by 13.
    100     Item with worry level 3136 is thrown to monkey 3.
    101 Monkey 3:
    102   Monkey inspects an item with a worry level of 74.
    103     Worry level increases by 3 to 77.
    104     Monkey gets bored with item. Worry level is divided by 3 to 25.
    105     Current worry level is not divisible by 17.
    106     Item with worry level 25 is thrown to monkey 1.
    107   Monkey inspects an item with a worry level of 500.
    108     Worry level increases by 3 to 503.
    109     Monkey gets bored with item. Worry level is divided by 3 to 167.
    110     Current worry level is not divisible by 17.
    111     Item with worry level 167 is thrown to monkey 1.
    112   Monkey inspects an item with a worry level of 620.
    113     Worry level increases by 3 to 623.
    114     Monkey gets bored with item. Worry level is divided by 3 to 207.
    115     Current worry level is not divisible by 17.
    116     Item with worry level 207 is thrown to monkey 1.
    117   Monkey inspects an item with a worry level of 1200.
    118     Worry level increases by 3 to 1203.
    119     Monkey gets bored with item. Worry level is divided by 3 to 401.
    120     Current worry level is not divisible by 17.
    121     Item with worry level 401 is thrown to monkey 1.
    122   Monkey inspects an item with a worry level of 3136.
    123     Worry level increases by 3 to 3139.
    124     Monkey gets bored with item. Worry level is divided by 3 to 1046.
    125     Current worry level is not divisible by 17.
    126     Item with worry level 1046 is thrown to monkey 1.
    127 
    128 After round 1, the monkeys are holding items with these worry levels:
    129 
    130 Monkey 0: 20, 23, 27, 26
    131 Monkey 1: 2080, 25, 167, 207, 401, 1046
    132 Monkey 2: 
    133 Monkey 3: 
    134 
    135 Monkeys 2 and 3 aren't holding any items at the end of the round; they both inspected items during the round and threw them all before the round ended.
    136 
    137 This process continues for a few more rounds:
    138 
    139 After round 2, the monkeys are holding items with these worry levels:
    140 Monkey 0: 695, 10, 71, 135, 350
    141 Monkey 1: 43, 49, 58, 55, 362
    142 Monkey 2: 
    143 Monkey 3: 
    144 
    145 After round 3, the monkeys are holding items with these worry levels:
    146 Monkey 0: 16, 18, 21, 20, 122
    147 Monkey 1: 1468, 22, 150, 286, 739
    148 Monkey 2: 
    149 Monkey 3: 
    150 
    151 After round 4, the monkeys are holding items with these worry levels:
    152 Monkey 0: 491, 9, 52, 97, 248, 34
    153 Monkey 1: 39, 45, 43, 258
    154 Monkey 2: 
    155 Monkey 3: 
    156 
    157 After round 5, the monkeys are holding items with these worry levels:
    158 Monkey 0: 15, 17, 16, 88, 1037
    159 Monkey 1: 20, 110, 205, 524, 72
    160 Monkey 2: 
    161 Monkey 3: 
    162 
    163 After round 6, the monkeys are holding items with these worry levels:
    164 Monkey 0: 8, 70, 176, 26, 34
    165 Monkey 1: 481, 32, 36, 186, 2190
    166 Monkey 2: 
    167 Monkey 3: 
    168 
    169 After round 7, the monkeys are holding items with these worry levels:
    170 Monkey 0: 162, 12, 14, 64, 732, 17
    171 Monkey 1: 148, 372, 55, 72
    172 Monkey 2: 
    173 Monkey 3: 
    174 
    175 After round 8, the monkeys are holding items with these worry levels:
    176 Monkey 0: 51, 126, 20, 26, 136
    177 Monkey 1: 343, 26, 30, 1546, 36
    178 Monkey 2: 
    179 Monkey 3: 
    180 
    181 After round 9, the monkeys are holding items with these worry levels:
    182 Monkey 0: 116, 10, 12, 517, 14
    183 Monkey 1: 108, 267, 43, 55, 288
    184 Monkey 2: 
    185 Monkey 3: 
    186 
    187 After round 10, the monkeys are holding items with these worry levels:
    188 Monkey 0: 91, 16, 20, 98
    189 Monkey 1: 481, 245, 22, 26, 1092, 30
    190 Monkey 2: 
    191 Monkey 3: 
    192 
    193 ...
    194 
    195 After round 15, the monkeys are holding items with these worry levels:
    196 Monkey 0: 83, 44, 8, 184, 9, 20, 26, 102
    197 Monkey 1: 110, 36
    198 Monkey 2: 
    199 Monkey 3: 
    200 
    201 ...
    202 
    203 After round 20, the monkeys are holding items with these worry levels:
    204 Monkey 0: 10, 12, 14, 26, 34
    205 Monkey 1: 245, 93, 53, 199, 115
    206 Monkey 2: 
    207 Monkey 3: 
    208 
    209 Chasing all of the monkeys at once is impossible; you're going to have to focus on the two most active monkeys if you want any hope of getting your stuff back. Count the total number of times each monkey inspects items over 20 rounds:
    210 
    211 Monkey 0 inspected items 101 times.
    212 Monkey 1 inspected items 95 times.
    213 Monkey 2 inspected items 7 times.
    214 Monkey 3 inspected items 105 times.
    215 
    216 In this example, the two most active monkeys inspected items 101 and 105 times. The level of monkey business in this situation can be found by multiplying these together: 10605.
    217 
    218 Figure out which monkeys to chase by counting how many items they inspect over 20 rounds. What is the level of monkey business after 20 rounds of stuff-slinging simian shenanigans?
    219 
    220 Your puzzle answer was 58786.
    221 --- Part Two ---
    222 
    223 You're worried you might not ever get your items back. So worried, in fact, that your relief that a monkey's inspection didn't damage an item no longer causes your worry level to be divided by three.
    224 
    225 Unfortunately, that relief was all that was keeping your worry levels from reaching ridiculous levels. You'll need to find another way to keep your worry levels manageable.
    226 
    227 At this rate, you might be putting up with these monkeys for a very long time - possibly 10000 rounds!
    228 
    229 With these new rules, you can still figure out the monkey business after 10000 rounds. Using the same example above:
    230 
    231 == After round 1 ==
    232 Monkey 0 inspected items 2 times.
    233 Monkey 1 inspected items 4 times.
    234 Monkey 2 inspected items 3 times.
    235 Monkey 3 inspected items 6 times.
    236 
    237 == After round 20 ==
    238 Monkey 0 inspected items 99 times.
    239 Monkey 1 inspected items 97 times.
    240 Monkey 2 inspected items 8 times.
    241 Monkey 3 inspected items 103 times.
    242 
    243 == After round 1000 ==
    244 Monkey 0 inspected items 5204 times.
    245 Monkey 1 inspected items 4792 times.
    246 Monkey 2 inspected items 199 times.
    247 Monkey 3 inspected items 5192 times.
    248 
    249 == After round 2000 ==
    250 Monkey 0 inspected items 10419 times.
    251 Monkey 1 inspected items 9577 times.
    252 Monkey 2 inspected items 392 times.
    253 Monkey 3 inspected items 10391 times.
    254 
    255 == After round 3000 ==
    256 Monkey 0 inspected items 15638 times.
    257 Monkey 1 inspected items 14358 times.
    258 Monkey 2 inspected items 587 times.
    259 Monkey 3 inspected items 15593 times.
    260 
    261 == After round 4000 ==
    262 Monkey 0 inspected items 20858 times.
    263 Monkey 1 inspected items 19138 times.
    264 Monkey 2 inspected items 780 times.
    265 Monkey 3 inspected items 20797 times.
    266 
    267 == After round 5000 ==
    268 Monkey 0 inspected items 26075 times.
    269 Monkey 1 inspected items 23921 times.
    270 Monkey 2 inspected items 974 times.
    271 Monkey 3 inspected items 26000 times.
    272 
    273 == After round 6000 ==
    274 Monkey 0 inspected items 31294 times.
    275 Monkey 1 inspected items 28702 times.
    276 Monkey 2 inspected items 1165 times.
    277 Monkey 3 inspected items 31204 times.
    278 
    279 == After round 7000 ==
    280 Monkey 0 inspected items 36508 times.
    281 Monkey 1 inspected items 33488 times.
    282 Monkey 2 inspected items 1360 times.
    283 Monkey 3 inspected items 36400 times.
    284 
    285 == After round 8000 ==
    286 Monkey 0 inspected items 41728 times.
    287 Monkey 1 inspected items 38268 times.
    288 Monkey 2 inspected items 1553 times.
    289 Monkey 3 inspected items 41606 times.
    290 
    291 == After round 9000 ==
    292 Monkey 0 inspected items 46945 times.
    293 Monkey 1 inspected items 43051 times.
    294 Monkey 2 inspected items 1746 times.
    295 Monkey 3 inspected items 46807 times.
    296 
    297 == After round 10000 ==
    298 Monkey 0 inspected items 52166 times.
    299 Monkey 1 inspected items 47830 times.
    300 Monkey 2 inspected items 1938 times.
    301 Monkey 3 inspected items 52013 times.
    302 
    303 After 10000 rounds, the two most active monkeys inspected items 52166 and 52013 times. Multiplying these together, the level of monkey business in this situation is now 2713310158.
    304 
    305 Worry levels are no longer divided by three after each item is inspected; you'll need to find another way to keep your worry levels manageable. Starting again from the initial state in your puzzle input, what is the level of monkey business after 10000 rounds?
    306 
    307 Your puzzle answer was 14952185856.