@@ -83,3 +83,110 @@ expected verification number and is currently running around the facility with i
8383
8484Run the HASH algorithm on each step in the initialization sequence. ** What is the sum of the results** ? (The
8585initialization sequence is one long line; be careful when copy-pasting it.)
86+
87+ # Part Two
88+ You convince the reindeer to bring you the page; the page confirms that your HASH algorithm is working.
89+
90+ The book goes on to describe a series of 256 ** boxes** numbered ` 0 ` through ` 255 ` . The boxes are arranged in a line
91+ starting from the point where light enters the facility. The boxes have holes that allow light to pass from one box
92+ to the next all the way down the line.
93+ ```
94+ +-----+ +-----+ +-----+
95+ Light | Box | | Box | ... | Box |
96+ ----------------------------------------->
97+ | 0 | | 1 | ... | 255 |
98+ +-----+ +-----+ +-----+
99+ ```
100+ Inside each box, there are several ** lens slots** that will keep a lens correctly positioned to focus light passing
101+ through the box. The side of each box has a panel that opens to allow you to insert or remove lenses as necessary.
102+
103+ Along the wall running parallel to the boxes is a large library containing lenses organized by ** focal length** ranging
104+ from ` 1 ` through ` 9 ` . The reindeer also brings you a small handheld
105+ [ label printer] ( https://en.wikipedia.org/wiki/Label_printer ) .
106+
107+ The book goes on to explain how to perform each step in the initialization sequence, a process it calls the Holiday
108+ ASCII String Helper Manual Arrangement Procedure, or ** HASHMAP** for short.
109+
110+ Each step begins with a sequence of letters that indicate the ** label** of the lens on which the step operates. The
111+ result of running the HASH algorithm on the label indicates the correct box for that step.
112+
113+ The label will be immediately followed by a character that indicates the ** operation** to perform: either an equals
114+ sign (` = ` ) or a dash (` - ` ).
115+
116+ If the operation character is a ** dash** (` - ` ), go to the relevant box and remove the lens with the given label if it
117+ is present in the box. Then, move any remaining lenses as far forward in the box as they can go without changing their
118+ order, filling any space made by removing the indicated lens. (If no lens in that box has the given label, nothing
119+ happens.)
120+
121+ If the operation character is an ** equals sign** (` = ` ), it will be followed by a number indicating the ** focal length**
122+ 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
123+ given in the beginning of the step so you can find it later. There are two possible situations:
124+ * If there is already a lens in the box with the same label, ** replace the old lens** with the new lens: remove the
125+ old lens and put the new lens in its place, not moving any other lenses in the box.
126+ * If there is ** not** already a lens in the box with the same label, add the lens to the box immediately behind any
127+ 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,
128+ the new lens goes all the way to the front of the box.
129+
130+ Here is the contents of every box after each step in the example initialization sequence above:
131+ ```
132+ After "rn=1":
133+ Box 0: [rn 1]
134+
135+ After "cm-":
136+ Box 0: [rn 1]
137+
138+ After "qp=3":
139+ Box 0: [rn 1]
140+ Box 1: [qp 3]
141+
142+ After "cm=2":
143+ Box 0: [rn 1] [cm 2]
144+ Box 1: [qp 3]
145+
146+ After "qp-":
147+ Box 0: [rn 1] [cm 2]
148+
149+ After "pc=4":
150+ Box 0: [rn 1] [cm 2]
151+ Box 3: [pc 4]
152+
153+ After "ot=9":
154+ Box 0: [rn 1] [cm 2]
155+ Box 3: [pc 4] [ot 9]
156+
157+ After "ab=5":
158+ Box 0: [rn 1] [cm 2]
159+ Box 3: [pc 4] [ot 9] [ab 5]
160+
161+ After "pc-":
162+ Box 0: [rn 1] [cm 2]
163+ Box 3: [ot 9] [ab 5]
164+
165+ After "pc=6":
166+ Box 0: [rn 1] [cm 2]
167+ Box 3: [ot 9] [ab 5] [pc 6]
168+
169+ After "ot=7":
170+ Box 0: [rn 1] [cm 2]
171+ Box 3: [ot 7] [ab 5] [pc 6]
172+ ```
173+ All 256 boxes are always present; only the boxes that contain any lenses are shown here. Within each box, lenses are
174+ listed from front to back; each lens is shown as its label and focal length in square brackets.
175+
176+ To confirm that all of the lenses are installed correctly, add up the ** focusing power** of all of the lenses. The
177+ focusing power of a single lens is the result of multiplying together:
178+ * One plus the box number of the lens in question.
179+ * The slot number of the lens within the box: ` 1 ` for the first lens, ` 2 ` for the second lens, and so on.
180+ * The focal length of the lens.
181+
182+ At the end of the above example, the focusing power of each lens is as follows:
183+ * ` rn ` : ` 1 ` (box 0) * ` 1 ` (first slot) * ` 1 ` (focal length) = ** ` 1 ` **
184+ * ` cm ` : ` 1 ` (box 0) * ` 2 ` (second slot) * ` 2 ` (focal length) = ** ` 4 ` **
185+ * ` ot ` : ` 4 ` (box 3) * ` 1 ` (first slot) * ` 7 ` (focal length) = ** ` 28 ` **
186+ * ` ab ` : ` 4 ` (box 3) * ` 2 ` (second slot) * ` 5 ` (focal length) = ** ` 40 ` **
187+ * ` pc ` : ` 4 ` (box 3) * ` 3 ` (third slot) * ` 6 ` (focal length) = ** ` 72 ` **
188+
189+ So, the above example ends up with a total focusing power of ** ` 145 ` ** .
190+
191+ With the help of an over-enthusiastic reindeer in a hard hat, follow the initialization sequence. ** What is the
192+ focusing power of the resulting lens configuration** ?
0 commit comments