description.txt 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. --- Day 15: Lens Library ---
  2. The newly-focused parabolic reflector dish is sending all of the collected light to a point on the side of yet another mountain - the largest mountain on Lava Island. As you approach the mountain, you find that the light is being collected by the wall of a large facility embedded in the mountainside.
  3. You find a door under a large sign that says "Lava Production Facility" and next to a smaller sign that says "Danger - Personal Protective Equipment required beyond this point".
  4. As you step inside, you are immediately greeted by a somewhat panicked reindeer wearing goggles and a loose-fitting hard hat. The reindeer leads you to a shelf of goggles and hard hats (you quickly find some that fit) and then further into the facility. At one point, you pass a button with a faint snout mark and the label "PUSH FOR HELP". No wonder you were loaded into that trebuchet so quickly!
  5. You pass through a final set of doors surrounded with even more warning signs and into what must be the room that collects all of the light from outside. As you admire the large assortment of lenses available to further focus the light, the reindeer brings you a book titled "Initialization Manual".
  6. "Hello!", the book cheerfully begins, apparently unaware of the concerned reindeer reading over your shoulder. "This procedure will let you bring the Lava Production Facility online - all without burning or melting anything unintended!"
  7. "Before you begin, please be prepared to use the Holiday ASCII String Helper algorithm (appendix 1A)." You turn to appendix 1A. The reindeer leans closer with interest.
  8. The HASH algorithm is a way to turn any string of characters into a single number in the range 0 to 255. To run the HASH algorithm on a string, start with a current value of 0. Then, for each character in the string starting from the beginning:
  9. Determine the ASCII code for the current character of the string.
  10. Increase the current value by the ASCII code you just determined.
  11. Set the current value to itself multiplied by 17.
  12. Set the current value to the remainder of dividing itself by 256.
  13. After following these steps for each character in the string in order, the current value is the output of the HASH algorithm.
  14. So, to find the result of running the HASH algorithm on the string HASH:
  15. The current value starts at 0.
  16. The first character is H; its ASCII code is 72.
  17. The current value increases to 72.
  18. The current value is multiplied by 17 to become 1224.
  19. The current value becomes 200 (the remainder of 1224 divided by 256).
  20. The next character is A; its ASCII code is 65.
  21. The current value increases to 265.
  22. The current value is multiplied by 17 to become 4505.
  23. The current value becomes 153 (the remainder of 4505 divided by 256).
  24. The next character is S; its ASCII code is 83.
  25. The current value increases to 236.
  26. The current value is multiplied by 17 to become 4012.
  27. The current value becomes 172 (the remainder of 4012 divided by 256).
  28. The next character is H; its ASCII code is 72.
  29. The current value increases to 244.
  30. The current value is multiplied by 17 to become 4148.
  31. The current value becomes 52 (the remainder of 4148 divided by 256).
  32. So, the result of running the HASH algorithm on the string HASH is 52.
  33. The initialization sequence (your puzzle input) is a comma-separated list of steps to start the Lava Production Facility. Ignore newline characters when parsing the initialization sequence. To verify that your HASH algorithm is working, the book offers the sum of the result of running the HASH algorithm on each step in the initialization sequence.
  34. For example:
  35. rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7
  36. This initialization sequence specifies 11 individual steps; the result of running the HASH algorithm on each of the steps is as follows:
  37. rn=1 becomes 30.
  38. cm- becomes 253.
  39. qp=3 becomes 97.
  40. cm=2 becomes 47.
  41. qp- becomes 14.
  42. pc=4 becomes 180.
  43. ot=9 becomes 9.
  44. ab=5 becomes 197.
  45. pc- becomes 48.
  46. pc=6 becomes 214.
  47. ot=7 becomes 231.
  48. In this example, the sum of these results is 1320. Unfortunately, the reindeer has stolen the page containing the expected verification number and is currently running around the facility with it excitedly.
  49. Run the HASH algorithm on each step in the initialization sequence. What is the sum of the results? (The initialization sequence is one long line; be careful when copy-pasting it.)
  50. Your puzzle answer was 517551.
  51. --- Part Two ---
  52. You convince the reindeer to bring you the page; the page confirms that your HASH algorithm is working.
  53. The book goes on to describe a series of 256 boxes numbered 0 through 255. The boxes are arranged in a line starting from the point where light enters the facility. The boxes have holes that allow light to pass from one box to the next all the way down the line.
  54. +-----+ +-----+ +-----+
  55. Light | Box | | Box | ... | Box |
  56. ----------------------------------------->
  57. | 0 | | 1 | ... | 255 |
  58. +-----+ +-----+ +-----+
  59. Inside each box, there are several lens slots that will keep a lens correctly positioned to focus light passing through the box. The side of each box has a panel that opens to allow you to insert or remove lenses as necessary.
  60. Along the wall running parallel to the boxes is a large library containing lenses organized by focal length ranging from 1 through 9. The reindeer also brings you a small handheld label printer.
  61. The book goes on to explain how to perform each step in the initialization sequence, a process it calls the Holiday ASCII String Helper Manual Arrangement Procedure, or HASHMAP for short.
  62. Each step begins with a sequence of letters that indicate the label of the lens on which the step operates. The result of running the HASH algorithm on the label indicates the correct box for that step.
  63. The label will be immediately followed by a character that indicates the operation to perform: either an equals sign (=) or a dash (-).
  64. If the operation character is a dash (-), go to the relevant box and remove the lens with the given label if it is present in the box. Then, move any remaining lenses as far forward in the box as they can go without changing their order, filling any space made by removing the indicated lens. (If no lens in that box has the given label, nothing happens.)
  65. If the operation character is an equals sign (=), it will be followed by a number indicating the focal length of the lens that needs to go into the relevant box; be sure to use the label maker to mark the lens with the label given in the beginning of the step so you can find it later. There are two possible situations:
  66. If there is already a lens in the box with the same label, replace the old lens with the new lens: remove the old lens and put the new lens in its place, not moving any other lenses in the box.
  67. If there is not already a lens in the box with the same label, add the lens to the box immediately behind any lenses already in the box. Don't move any of the other lenses when you do this. If there aren't any lenses in the box, the new lens goes all the way to the front of the box.
  68. Here is the contents of every box after each step in the example initialization sequence above:
  69. After "rn=1":
  70. Box 0: [rn 1]
  71. After "cm-":
  72. Box 0: [rn 1]
  73. After "qp=3":
  74. Box 0: [rn 1]
  75. Box 1: [qp 3]
  76. After "cm=2":
  77. Box 0: [rn 1] [cm 2]
  78. Box 1: [qp 3]
  79. After "qp-":
  80. Box 0: [rn 1] [cm 2]
  81. After "pc=4":
  82. Box 0: [rn 1] [cm 2]
  83. Box 3: [pc 4]
  84. After "ot=9":
  85. Box 0: [rn 1] [cm 2]
  86. Box 3: [pc 4] [ot 9]
  87. After "ab=5":
  88. Box 0: [rn 1] [cm 2]
  89. Box 3: [pc 4] [ot 9] [ab 5]
  90. After "pc-":
  91. Box 0: [rn 1] [cm 2]
  92. Box 3: [ot 9] [ab 5]
  93. After "pc=6":
  94. Box 0: [rn 1] [cm 2]
  95. Box 3: [ot 9] [ab 5] [pc 6]
  96. After "ot=7":
  97. Box 0: [rn 1] [cm 2]
  98. Box 3: [ot 7] [ab 5] [pc 6]
  99. All 256 boxes are always present; only the boxes that contain any lenses are shown here. Within each box, lenses are listed from front to back; each lens is shown as its label and focal length in square brackets.
  100. To confirm that all of the lenses are installed correctly, add up the focusing power of all of the lenses. The focusing power of a single lens is the result of multiplying together:
  101. One plus the box number of the lens in question.
  102. The slot number of the lens within the box: 1 for the first lens, 2 for the second lens, and so on.
  103. The focal length of the lens.
  104. At the end of the above example, the focusing power of each lens is as follows:
  105. rn: 1 (box 0) * 1 (first slot) * 1 (focal length) = 1
  106. cm: 1 (box 0) * 2 (second slot) * 2 (focal length) = 4
  107. ot: 4 (box 3) * 1 (first slot) * 7 (focal length) = 28
  108. ab: 4 (box 3) * 2 (second slot) * 5 (focal length) = 40
  109. pc: 4 (box 3) * 3 (third slot) * 6 (focal length) = 72
  110. So, the above example ends up with a total focusing power of 145.
  111. With the help of an over-enthusiastic reindeer in a hard hat, follow the initialization sequence. What is the focusing power of the resulting lens configuration?
  112. Your puzzle answer was 286097.
  113. Both parts of this puzzle are complete! They provide two gold stars: **