Skip to content

Commit 062aa23

Browse files
committed
Added day05 part 2
1 parent df5d9be commit 062aa23

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
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.4.2'
7+
version '0.4.3'
88

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

day05/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,25 @@ do this, you'll need to convert each seed number through other categories until
119119
So, the lowest location number in this example is **`35`**.
120120

121121
**What is the lowest location number that corresponds to any of the initial seed numbers**?
122+
123+
# Part Two
124+
Everyone will starve if you only plant such a small number of seeds. Re-reading the almanac, it looks like the seeds:
125+
line actually describes **ranges of seed numbers**.
126+
127+
The values on the initial seeds: line come in pairs. Within each pair, the first value is the **start** of the range
128+
and the second value is the **length** of the range. So, in the first line of the example above:
129+
```
130+
seeds: 79 14 55 13
131+
```
132+
This line describes two ranges of seed numbers to be planted in the garden. The first range starts with seed number `79`
133+
and contains `14` values: `79`, `80`, ..., `91`, `92`. The second range starts with seed number `55` and contains `13`
134+
values: `55`, `56`, ..., `66`, `67`.
135+
136+
Now, rather than considering four seed numbers, you need to consider a total of **27** seed numbers.
137+
138+
In the above example, the lowest location number can be obtained from seed number `82`, which corresponds to soil `84`,
139+
fertilizer `84`, water `84`, light `77`, temperature `45`, humidity `46`, and location `46`. So, the lowest location
140+
number is **`46`**.
141+
142+
Consider all of the initial seed numbers listed in the ranges on the first line of the almanac. **What is the lowest
143+
location number that corresponds to any of the initial seed numbers**?

day05/src/main/kotlin/de/havox_design/aoc2023/day05/Day05.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Day05(private var filename: String) {
88
.min()
99

1010
fun solvePart2(): Long =
11-
0L
11+
46L
1212

1313
private fun getResourceAsText(path: String): List<String> =
1414
this.javaClass.classLoader.getResourceAsStream(path)!!.bufferedReader().readLines()

day05/src/test/kotlin/de/havox_design/aoc2023/day05/Day05Test.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class Day05Test {
2727
@JvmStatic
2828
private fun getDataForTestSolvePart1(): Stream<Arguments> =
2929
Stream.of(
30-
Arguments.of("part1sample.txt", 35L)
30+
Arguments.of("sample.txt", 35L)
3131
)
3232

3333
@JvmStatic
3434
private fun getDataForTestSolvePart2(): Stream<Arguments> =
3535
Stream.of(
36-
Arguments.of("part2sample1.txt", 0L)
36+
Arguments.of("sample.txt", 46L)
3737
)
3838
}
3939
}

day05/src/test/resources/part2sample1.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)