Skip to content

Commit 394b77d

Browse files
committed
Added day12 part 1
1 parent c006f65 commit 394b77d

File tree

7 files changed

+1109
-3
lines changed

7 files changed

+1109
-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.11.0'
7+
version '0.11.1'
88

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

day12/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Day 12: Hot Springs
2+
You finally reach the hot springs! You can see steam rising from secluded areas attached to the primary, ornate
3+
building.
4+
5+
As you turn to enter, the [researcher](https://adventofcode.com/2023/day/11) stops you. "Wait - I thought you were
6+
looking for the hot springs, weren't you?" You indicate that this definitely looks like hot springs to you.
7+
8+
"Oh, sorry, common mistake! This is actually the [onsen](https://en.wikipedia.org/wiki/Onsen)! The hot springs are
9+
next door."
10+
11+
You look in the direction the researcher is pointing and suddenly notice the massive metal helixes towering overhead.
12+
"This way!"
13+
14+
It only takes you a few more steps to reach the main gate of the massive fenced-off area containing the springs. You
15+
go through the gate and into a small administrative building.
16+
17+
"Hello! What brings you to the hot springs today? Sorry they're not very hot right now; we're having a **lava
18+
shortage** at the moment." You ask about the missing machine parts for Desert Island.
19+
20+
"Oh, all of Gear Island is currently offline! Nothing is being manufactured at the moment, not until we get more lava
21+
to heat our forges. And our springs. The springs aren't very springy unless they're hot!"
22+
23+
"Say, could you go up and see why the lava stopped flowing? The springs are too cold for normal operation, but we
24+
should be able to find one springy enough to launch **you** up there!"
25+
26+
There's just one problem - many of the springs have fallen into disrepair, so they're not actually sure which springs
27+
would even be **safe** to use! Worse yet, their **condition records of which springs are damaged** (your puzzle input)
28+
are also damaged! You'll need to help them repair the damaged records.
29+
30+
In the giant field just outside, the springs are arranged into rows. For each row, the condition records show every
31+
spring and whether it is **operational** (`.`) or **damaged** (`#`). This is the part of the condition records that is
32+
itself damaged; for some springs, it is simply **unknown** (`?`) whether the spring is operational or damaged.
33+
34+
However, the engineer that produced the condition records also duplicated some of this information in a different
35+
format! After the list of springs for a given row, the size of each **contiguous group of damaged springs** is listed
36+
in the order those groups appear in the row. This list always accounts for every damaged spring, and each number is
37+
the entire size of its contiguous group (that is, groups are always separated by at least one operational spring:
38+
`####` would always be `4`, never `2,2`).
39+
40+
So, condition records with no unknown spring conditions might look like this:
41+
```
42+
#.#.### 1,1,3
43+
.#...#....###. 1,1,3
44+
.#.###.#.###### 1,3,1,6
45+
####.#...#... 4,1,1
46+
#....######..#####. 1,6,5
47+
.###.##....# 3,2,1
48+
```
49+
However, the condition records are partially damaged; some of the springs' conditions are actually **unknown** (`?`).
50+
For example:
51+
```
52+
???.### 1,1,3
53+
.??..??...?##. 1,1,3
54+
?#?#?#?#?#?#?#? 1,3,1,6
55+
????.#...#... 4,1,1
56+
????.######..#####. 1,6,5
57+
?###???????? 3,2,1
58+
```
59+
Equipped with this information, it is your job to figure out **how many different arrangements** of operational and
60+
broken springs fit the given criteria in each row.
61+
62+
In the first line (`???.### 1,1,3`), there is exactly **one** way separate groups of one, one, and three broken
63+
springs (in that order) can appear in that row: the first three unknown springs must be broken, then operational, then
64+
broken (`#.#`), making the whole row `#.#.###`.
65+
66+
The second line is more interesting: `.??..??...?##. 1,1,3` could be a total of **four** different arrangements. The
67+
last `?` must always be broken (to satisfy the final contiguous group of three broken springs), and each `??` must hide
68+
exactly one of the two broken springs. (Neither `??` could be both broken springs or they would form a single
69+
contiguous group of two; if that were true, the numbers afterward would have been `2,3` instead.) Since each `??` can
70+
either be `#.` or `.#`, there are four possible arrangements of springs.
71+
72+
The last line is actually consistent with **ten** different arrangements! Because the first number is `3`, the first and
73+
second `?` must both be `.` (if either were `#`, the first number would have to be `4` or higher). However, the
74+
remaining run of unknown spring conditions have many different ways they could hold groups of two and one broken
75+
springs:
76+
```
77+
?###???????? 3,2,1
78+
.###.##.#...
79+
.###.##..#..
80+
.###.##...#.
81+
.###.##....#
82+
.###..##.#..
83+
.###..##..#.
84+
.###..##...#
85+
.###...##.#.
86+
.###...##..#
87+
.###....##.#
88+
```
89+
In this example, the number of possible arrangements for each row is:
90+
* `???.### 1,1,3` - **`1` arrangement**
91+
* `.??..??...?##. 1,1,3` - **`4` arrangements**
92+
* `?#?#?#?#?#?#?#? 1,3,1,6` - **`1` arrangement**
93+
* `????.#...#... 4,1,1` - **`1` arrangement**
94+
* `????.######..#####. 1,6,5` - **`4` arrangements**
95+
* `?###???????? 3,2,1` - **`10` arrangements**
96+
97+
Adding all of the possible arrangement counts together produces a total of **`21`** arrangements.
98+
99+
For each row, count all of the different arrangements of operational and broken springs that meet the given criteria.
100+
**What is the sum of those counts?**

day12/src/main/kotlin/de/havox_design/aoc2023/day12/Day12.kt

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

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

77
fun solvePart2(): Long =
88
0L

0 commit comments

Comments
 (0)