|
| 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 |
| 3 | +mountain - the largest mountain on Lava Island. As you approach the mountain, you find that the light is being |
| 4 | +collected by the wall of a large facility embedded in the mountainside. |
| 5 | + |
| 6 | +You find a door under a large sign that says "Lava Production Facility" and next to a smaller sign that says "Danger - |
| 7 | +Personal Protective Equipment required beyond this point". |
| 8 | + |
| 9 | +As you step inside, you are immediately greeted by a somewhat panicked reindeer wearing goggles and a loose-fitting |
| 10 | +[hard hat](https://en.wikipedia.org/wiki/Hard_hat). The reindeer leads you to a shelf of goggles and hard hats (you |
| 11 | +quickly find some that fit) and then further into the facility. At one point, you pass a button with a faint snout |
| 12 | +mark and the label "PUSH FOR HELP". No wonder you were loaded into that [trebuchet](https://adventofcode.com/2023/day/1) |
| 13 | +so quickly! |
| 14 | + |
| 15 | +You pass through a final set of doors surrounded with even more warning signs and into what must be the room that |
| 16 | +collects all of the light from outside. As you admire the large assortment of lenses available to further focus the |
| 17 | +light, the reindeer brings you a book titled "Initialization Manual". |
| 18 | + |
| 19 | +"Hello!", the book cheerfully begins, apparently unaware of the concerned reindeer reading over your shoulder. "This |
| 20 | +procedure will let you bring the Lava Production Facility online - all without burning or melting anything unintended!" |
| 21 | + |
| 22 | +"Before you begin, please be prepared to use the Holiday ASCII String Helper algorithm (appendix 1A)." You turn to |
| 23 | +appendix 1A. The reindeer leans closer with interest. |
| 24 | + |
| 25 | +The HASH algorithm is a way to turn any [string](https://en.wikipedia.org/wiki/String_(computer_science)) of characters |
| 26 | +into a single **number** in the range `0` to `255`. To run the HASH algorithm on a string, start with a **current |
| 27 | +value** of `0`. Then, for each character in the string starting from the beginning: |
| 28 | +* Determine the [ASCII code](https://en.wikipedia.org/wiki/ASCII#Printable_characters) for the current character of the |
| 29 | +string. |
| 30 | +* Increase the **current value** by the ASCII code you just determined. |
| 31 | +* Set the **current value** to itself multiplied by `17`. |
| 32 | +* Set the **current value** to the [remainder](https://en.wikipedia.org/wiki/Modulo) of dividing itself by `256`. |
| 33 | + |
| 34 | +After following these steps for each character in the string in order, the **current value** is the output of the HASH |
| 35 | +algorithm. |
| 36 | + |
| 37 | +So, to find the result of running the HASH algorithm on the string `HASH`: |
| 38 | +* The **current value** starts at `0`. |
| 39 | +* The first character is `H`; its ASCII code is `72`. |
| 40 | +* The **current value** increases to `72`. |
| 41 | +* The **current value** is multiplied by `17` to become `1224`. |
| 42 | +* The **current value** becomes **`200`** (the remainder of `1224` divided by `256`). |
| 43 | +* The next character is `A`; its ASCII code is `65`. |
| 44 | +* The **current value** increases to `265`. |
| 45 | +* The **current value** is multiplied by `17` to become `4505`. |
| 46 | +* The **current value** becomes **`153`** (the remainder of `4505` divided by `256`). |
| 47 | +* The next character is `S`; its ASCII code is `83`. |
| 48 | +* The **current value** increases to `236`. |
| 49 | +* The **current value** is multiplied by `17` to become `4012`. |
| 50 | +* The **current value** becomes **`172`** (the remainder of `4012` divided by `256`). |
| 51 | +* The next character is `H`; its ASCII code is `72`. |
| 52 | +* The **current value** increases to `244`. |
| 53 | +* The **current value** is multiplied by `17` to become `4148`. |
| 54 | +* The **current value** becomes **`52`** (the remainder of `4148` divided by `256`). |
| 55 | + |
| 56 | +So, the result of running the HASH algorithm on the string HASH is **`52`**. |
| 57 | + |
| 58 | +The **initialization sequence** (your puzzle input) is a comma-separated list of steps to start the Lava Production |
| 59 | +Facility. **Ignore newline characters** when parsing the initialization sequence. To verify that your HASH algorithm is |
| 60 | +working, the book offers the sum of the result of running the HASH algorithm on each step in the initialization |
| 61 | +sequence. |
| 62 | + |
| 63 | +For example: |
| 64 | +``` |
| 65 | +rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7 |
| 66 | +``` |
| 67 | +This initialization sequence specifies 11 individual steps; the result of running the HASH algorithm on each of the |
| 68 | +steps is as follows: |
| 69 | +* `rn=1` becomes **`30`**. |
| 70 | +* `cm-` becomes **`253`**. |
| 71 | +* `qp=3` becomes **`97`**. |
| 72 | +* `cm=2` becomes **`47`**. |
| 73 | +* `qp-` becomes **`14`**. |
| 74 | +* `pc=4` becomes **`180`**. |
| 75 | +* `ot=9` becomes **`9`**. |
| 76 | +* `ab=5` becomes **`197`**. |
| 77 | +* `pc-` becomes **`48`**. |
| 78 | +* `pc=6` becomes **`214`**. |
| 79 | +* `ot=7` becomes **`231`**. |
| 80 | + |
| 81 | +In this example, the sum of these results is **`1320`**. Unfortunately, the reindeer has stolen the page containing the |
| 82 | +expected verification number and is currently running around the facility with it excitedly. |
| 83 | + |
| 84 | +Run the HASH algorithm on each step in the initialization sequence. **What is the sum of the results**? (The |
| 85 | +initialization sequence is one long line; be careful when copy-pasting it.) |
0 commit comments