Skip to content

Commit aa725b2

Browse files
committed
Added day09 part 2
1 parent 17726a8 commit aa725b2

File tree

8 files changed

+34
-6
lines changed

8 files changed

+34
-6
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.8.3'
7+
version '0.8.4'
88

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

day09/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,28 @@ If you find the next value for each history in this example and add them togethe
8989

9090
Analyze your OASIS report and extrapolate the next value for each history. **What is the sum of these extrapolated
9191
values**?
92+
93+
# Part Two
94+
Of course, it would be nice to have **even more history** included in your report. Surely it's safe to just
95+
**extrapolate backwards** as well, right?
96+
97+
For each history, repeat the process of finding differences until the sequence of differences is entirely zero. Then,
98+
rather than adding a zero to the end and filling in the next values of each previous sequence, you should instead add
99+
a zero to the **beginning** of your sequence of zeroes, then fill in new **first** values for each previous sequence.
100+
101+
In particular, here is what the third example history looks like when extrapolating back in time:
102+
```
103+
_5_ 10 13 16 21 30 45
104+
_5_ 3 3 5 9 15
105+
_-2_ 0 2 4 6
106+
_2_ 2 2 2
107+
_0_ 0 0
108+
```
109+
Adding the new values on the left side of each sequence from bottom to top eventually reveals the new left-most history
110+
value: **`5`**.
111+
112+
Doing this for the remaining example data above results in previous values of **`-3`** for the first history and **`0`**
113+
for the second history. Adding all three new values together produces **`2`**.
114+
115+
Analyze your OASIS report again, this time extrapolating the previous value for each history. **What is the sum of
116+
these extrapolated values**?

day09/src/test/kotlin/de/havox_design/aoc2023/day09/Day09Test.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ class Day09Test {
2727
@JvmStatic
2828
private fun getDataForTestSolvePart1(): Stream<Arguments> =
2929
Stream.of(
30-
Arguments.of("part1sample1.txt", 18L),
31-
Arguments.of("part1sample2.txt", 28L),
32-
Arguments.of("part1sample3.txt", 68L),
33-
Arguments.of("part1sample4.txt", 114L)
30+
Arguments.of("sample1.txt", 18L),
31+
Arguments.of("sample2.txt", 28L),
32+
Arguments.of("sample3.txt", 68L),
33+
Arguments.of("sample4.txt", 114L)
3434
)
3535

3636
@JvmStatic
3737
private fun getDataForTestSolvePart2(): Stream<Arguments> =
3838
Stream.of(
39-
Arguments.of("part2sample1.txt", 0L)
39+
Arguments.of("sample1.txt", 0L),
40+
Arguments.of("sample2.txt", 0L),
41+
Arguments.of("sample3.txt", 0L),
42+
Arguments.of("sample4.txt", 0L)
4043
)
4144
}
4245
}

day09/src/test/resources/part2sample1.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)