part1 (2852B)
1--- Day 7: The Sum of Its Parts --- 2 3You find yourself standing on a snow-covered coastline; apparently, you landed a little off course. 4The region is too hilly to see the North Pole from here, but you do spot some Elves that seem to be 5trying to unpack something that washed ashore. It's quite cold out, so you decide to risk creating a 6paradox by asking them for directions. 7 8"Oh, are you the search party?" Somehow, you can understand whatever Elves from the year 1018 speak; 9you assume it's Ancient Nordic Elvish. Could the device on your wrist also be a translator? "Those 10clothes don't look very warm; take this." They hand you a heavy coat. 11 12"We do need to find our way back to the North Pole, but we have higher priorities at the moment. You 13see, believe it or not, this box contains something that will solve all of Santa's transportation 14problems - at least, that's what it looks like from the pictures in the instructions." It doesn't 15seem like they can read whatever language it's in, but you can: "Sleigh kit. Some assembly 16required." 17 18"'Sleigh'? What a wonderful name! You must help us assemble this 'sleigh' at once!" They start 19excitedly pulling more parts out of the box. 20 21The instructions specify a series of [1m[97msteps[0m and requirements about which steps must be finished 22before others can begin (your puzzle input). Each step is designated by a single letter. For 23example, suppose you have the following instructions: 24 25Step C must be finished before step A can begin. 26Step C must be finished before step F can begin. 27Step A must be finished before step B can begin. 28Step A must be finished before step D can begin. 29Step B must be finished before step E can begin. 30Step D must be finished before step E can begin. 31Step F must be finished before step E can begin. 32 33Visually, these requirements look like this: 34 35 -->A--->B-- 36 / \ \ 37C -->D----->E 38 \ / 39 ---->F----- 40 41Your first goal is to determine the order in which the steps should be completed. If more than one 42step is ready, choose the step which is first alphabetically. In this example, the steps would be 43completed as follows: 44 45 46 - Only [1m[97mC[0m is available, and so it is done first. 47 48 - Next, both A and F are available. [1m[97mA[0m is first alphabetically, so it is done next. 49 50 - Then, even though F was available earlier, steps B and D are now also available, and 51[1m[97mB[0m is the first alphabetically of the three. 52 53 - After that, only D and F are available. E is not available because only some of its prerequisites 54are complete. Therefore, [1m[97mD[0m is completed next. 55 56 - [1m[97mF[0m is the only choice, so it is done next. 57 58 - Finally, [1m[97mE[0m is completed. 59 60 61So, in this example, the correct order is [1m[97mCABDFE[0m. 62 63[1m[97mIn what order should the steps in your instructions be completed?[0m 64 65