task.txt (4160B)
1 --- Day 5: Supply Stacks --- 2 3 The expedition can depart as soon as the final supplies have been unloaded from the ships. Supplies are stored in stacks of marked crates, but because the needed supplies are buried under many other crates, the crates need to be rearranged. 4 5 The ship has a giant cargo crane capable of moving crates between stacks. To ensure none of the crates get crushed or fall over, the crane operator will rearrange them in a series of carefully-planned steps. After the crates are rearranged, the desired crates will be at the top of each stack. 6 7 The Elves don't want to interrupt the crane operator during this delicate procedure, but they forgot to ask her which crate will end up where, and they want to be ready to unload them as soon as possible so they can embark. 8 9 They do, however, have a drawing of the starting stacks of crates and the rearrangement procedure (your puzzle input). For example: 10 11 [D] 12 [N] [C] 13 [Z] [M] [P] 14 1 2 3 15 16 move 1 from 2 to 1 17 move 3 from 1 to 3 18 move 2 from 2 to 1 19 move 1 from 1 to 2 20 21 In this example, there are three stacks of crates. Stack 1 contains two crates: crate Z is on the bottom, and crate N is on top. Stack 2 contains three crates; from bottom to top, they are crates M, C, and D. Finally, stack 3 contains a single crate, P. 22 23 Then, the rearrangement procedure is given. In each step of the procedure, a quantity of crates is moved from one stack to a different stack. In the first step of the above rearrangement procedure, one crate is moved from stack 2 to stack 1, resulting in this configuration: 24 25 [D] 26 [N] [C] 27 [Z] [M] [P] 28 1 2 3 29 30 In the second step, three crates are moved from stack 1 to stack 3. Crates are moved one at a time, so the first crate to be moved (D) ends up below the second and third crates: 31 32 [Z] 33 [N] 34 [C] [D] 35 [M] [P] 36 1 2 3 37 38 Then, both crates are moved from stack 2 to stack 1. Again, because crates are moved one at a time, crate C ends up below crate M: 39 40 [Z] 41 [N] 42 [M] [D] 43 [C] [P] 44 1 2 3 45 46 Finally, one crate is moved from stack 1 to stack 2: 47 48 [Z] 49 [N] 50 [D] 51 [C] [M] [P] 52 1 2 3 53 54 The Elves just need to know which crate will end up on top of each stack; in this example, the top crates are C in stack 1, M in stack 2, and Z in stack 3, so you should combine these together and give the Elves the message CMZ. 55 56 After the rearrangement procedure completes, what crate ends up on top of each stack? 57 58 Your puzzle answer was SBPQRSCDF. 59 --- Part Two --- 60 61 As you watch the crane operator expertly rearrange the crates, you notice the process isn't following your prediction. 62 63 Some mud was covering the writing on the side of the crane, and you quickly wipe it away. The crane isn't a CrateMover 9000 - it's a CrateMover 9001. 64 65 The CrateMover 9001 is notable for many new and exciting features: air conditioning, leather seats, an extra cup holder, and the ability to pick up and move multiple crates at once. 66 67 Again considering the example above, the crates begin in the same configuration: 68 69 [D] 70 [N] [C] 71 [Z] [M] [P] 72 1 2 3 73 74 Moving a single crate from stack 2 to stack 1 behaves the same as before: 75 76 [D] 77 [N] [C] 78 [Z] [M] [P] 79 1 2 3 80 81 However, the action of moving three crates from stack 1 to stack 3 means that those three moved crates stay in the same order, resulting in this new configuration: 82 83 [D] 84 [N] 85 [C] [Z] 86 [M] [P] 87 1 2 3 88 89 Next, as both crates are moved from stack 2 to stack 1, they retain their order as well: 90 91 [D] 92 [N] 93 [C] [Z] 94 [M] [P] 95 1 2 3 96 97 Finally, a single crate is still moved from stack 1 to stack 2, but now it's crate C that gets moved: 98 99 [D] 100 [N] 101 [Z] 102 [M] [C] [P] 103 1 2 3 104 105 In this example, the CrateMover 9001 has put the crates in a totally different order: MCD. 106 107 Before the rearrangement process finishes, update your simulation so that the Elves know where they should stand to be ready to unload the final supplies. After the rearrangement procedure completes, what crate ends up on top of each stack? 108 109 Your puzzle answer was RGLVRCQSB.