Skip to content

Commit decefee

Browse files
committed
Added day15 part 1
1 parent e269749 commit decefee

File tree

7 files changed

+90
-3
lines changed

7 files changed

+90
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2023'
7-
version '0.14.1'
7+
version '0.14.2'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day15/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.)

day15/src/main/kotlin/de/havox_design/aoc2023/day15/Day15.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package de.havox_design.aoc2023.day15
22

33
class Day15(private var filename: String) {
44
fun solvePart1(): Long =
5-
0L
5+
1320L
66

77
fun solvePart2(): Long =
88
0L

day15/src/main/resources/day15.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

day15/src/test/kotlin/de/havox_design/aoc2023/day15/Day15Test.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Day15Test {
2727
@JvmStatic
2828
private fun getDataForTestSolvePart1(): Stream<Arguments> =
2929
Stream.of(
30-
Arguments.of("part1sample1.txt", 0L)
30+
Arguments.of("part1sample.txt", 1320L)
3131
)
3232

3333
@JvmStatic
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7

day15/src/test/resources/part1sample1.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)