|
| 1 | +--- Day 1: Historian Hysteria --- |
| 2 | + |
| 3 | + The Chief Historian is always present for the big Christmas sleigh |
| 4 | + launch, but nobody has seen him in months! Last anyone heard, he was |
| 5 | + visiting locations that are historically significant to the North Pole; |
| 6 | + a group of Senior Historians has asked you to accompany them as they |
| 7 | + check the places they think he was most likely to visit. |
| 8 | + |
| 9 | + As each location is checked, they will mark it on their list with a |
| 10 | + star . They figure the Chief Historian must be in one of the first |
| 11 | + fifty places they'll look, so in order to save Christmas, you need to |
| 12 | + help them get fifty stars on their list before Santa takes off on |
| 13 | + December 25th. |
| 14 | + |
| 15 | + Collect stars by solving puzzles. Two puzzles will be made available on |
| 16 | + each day in the Advent calendar; the second puzzle is unlocked when you |
| 17 | + complete the first. Each puzzle grants one star . Good luck! |
| 18 | + |
| 19 | + You haven't even left yet and the group of Elvish Senior Historians has |
| 20 | + already hit a problem: their list of locations to check is currently |
| 21 | + empty . Eventually, someone decides that the best place to check first |
| 22 | + would be the Chief Historian's office. |
| 23 | + |
| 24 | + Upon pouring into the office, everyone confirms that the Chief |
| 25 | + Historian is indeed nowhere to be found. Instead, the Elves discover an |
| 26 | + assortment of notes and lists of historically significant locations! |
| 27 | + This seems to be the planning the Chief Historian was doing before he |
| 28 | + left. Perhaps these notes can be used to determine which locations to |
| 29 | + search? |
| 30 | + |
| 31 | + Throughout the Chief's office, the historically significant locations |
| 32 | + are listed not by name but by a unique number called the location ID . |
| 33 | + To make sure they don't miss anything, The Historians split into two |
| 34 | + groups, each searching the office and trying to create their own |
| 35 | + complete list of location IDs. |
| 36 | + |
| 37 | + There's just one problem: by holding the two lists up side by side |
| 38 | + (your puzzle input), it quickly becomes clear that the lists aren't |
| 39 | + very similar. Maybe you can help The Historians reconcile their lists? |
| 40 | + |
| 41 | + For example: |
| 42 | + |
| 43 | + 3 4 |
| 44 | + 4 3 |
| 45 | + 2 5 |
| 46 | + 1 3 |
| 47 | + 3 9 |
| 48 | + 3 3 |
| 49 | + |
| 50 | + Maybe the lists are only off by a small amount! To find out, pair up |
| 51 | + the numbers and measure how far apart they are. Pair up the smallest |
| 52 | + number in the left list with the smallest number in the right list , |
| 53 | + then the second-smallest left number with the second-smallest right |
| 54 | + number , and so on. |
| 55 | + |
| 56 | + Within each pair, figure out how far apart the two numbers are; you'll |
| 57 | + need to add up all of those distances . For example, if you pair up a 3 |
| 58 | + from the left list with a 7 from the right list, the distance apart is |
| 59 | + 4 ; if you pair up a 9 with a 3 , the distance apart is 6 . |
| 60 | + |
| 61 | + In the example list above, the pairs and distances would be as follows: |
| 62 | + * The smallest number in the left list is 1 , and the smallest number |
| 63 | + in the right list is 3 . The distance between them is 2 . |
| 64 | + * The second-smallest number in the left list is 2 , and the |
| 65 | + second-smallest number in the right list is another 3 . The |
| 66 | + distance between them is 1 . |
| 67 | + * The third-smallest number in both lists is 3 , so the distance |
| 68 | + between them is 0 . |
| 69 | + * The next numbers to pair up are 3 and 4 , a distance of 1 . |
| 70 | + * The fifth-smallest numbers in each list are 3 and 5 , a distance of |
| 71 | + 2 . |
| 72 | + * Finally, the largest number in the left list is 4 , while the |
| 73 | + largest number in the right list is 9 ; these are a distance 5 |
| 74 | + apart. |
| 75 | + |
| 76 | + To find the total distance between the left list and the right list, |
| 77 | + add up the distances between all of the pairs you found. In the example |
| 78 | + above, this is 2 + 1 + 0 + 1 + 2 + 5 , a total distance of 11 ! |
| 79 | + |
| 80 | + Your actual left and right lists contain many location IDs. What is the |
| 81 | + total distance between your lists? |
| 82 | + |
| 83 | +--- Part Two --- |
| 84 | + |
| 85 | + Your analysis only confirmed what everyone feared: the two lists of |
| 86 | + location IDs are indeed very different. |
| 87 | + |
| 88 | + Or are they? |
| 89 | + |
| 90 | + The Historians can't agree on which group made the mistakes or how to |
| 91 | + read most of the Chief's handwriting, but in the commotion you notice |
| 92 | + an interesting detail: a lot of location IDs appear in both lists! |
| 93 | + Maybe the other numbers aren't location IDs at all but rather |
| 94 | + misinterpreted handwriting. |
| 95 | + |
| 96 | + This time, you'll need to figure out exactly how often each number from |
| 97 | + the left list appears in the right list. Calculate a total similarity |
| 98 | + score by adding up each number in the left list after multiplying it by |
| 99 | + the number of times that number appears in the right list. |
| 100 | + |
| 101 | + Here are the same example lists again: |
| 102 | + |
| 103 | + 3 4 |
| 104 | + 4 3 |
| 105 | + 2 5 |
| 106 | + 1 3 |
| 107 | + 3 9 |
| 108 | + 3 3 |
| 109 | + |
| 110 | + For these example lists, here is the process of finding the similarity |
| 111 | + score: |
| 112 | + * The first number in the left list is 3 . It appears in the right |
| 113 | + list three times, so the similarity score increases by 3 * 3 = 9 . |
| 114 | + * The second number in the left list is 4 . It appears in the right |
| 115 | + list once, so the similarity score increases by 4 * 1 = 4 . |
| 116 | + * The third number in the left list is 2 . It does not appear in the |
| 117 | + right list, so the similarity score does not increase ( 2 * 0 = 0 |
| 118 | + ). |
| 119 | + * The fourth number, 1 , also does not appear in the right list. |
| 120 | + * The fifth number, 3 , appears in the right list three times; the |
| 121 | + similarity score increases by 9 . |
| 122 | + * The last number, 3 , appears in the right list three times; the |
| 123 | + similarity score again increases by 9 . |
| 124 | + |
| 125 | + So, for these example lists, the similarity score at the end of this |
| 126 | + process is 31 ( 9 + 4 + 0 + 0 + 9 + 9 ). |
| 127 | + |
| 128 | + Once again consider your left and right lists. What is their similarity |
| 129 | + score? |
0 commit comments