File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed
main/kotlin/de/havox_design/aoc2023/day09
test/kotlin/de/havox_design/aoc2023/day09 Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ plugins {
44
55// project meta data
66group ' de.havox_design.aoc2023'
7- version ' 0.8.2 '
7+ version ' 0.8.3 '
88
99// Switch to gradle "all" distribution.
1010wrapper {
Original file line number Diff line number Diff line change @@ -2,11 +2,38 @@ package de.havox_design.aoc2023.day09
22
33class Day09 (private var filename : String ) {
44 fun solvePart1 (): Long =
5- 0L
5+ convertInput()
6+ .sumOf { history ->
7+ processOasisReport(history)
8+ }
69
710 fun solvePart2 (): Long =
811 0L
912
13+ private fun processOasisReport (oasisHistory : List <Long >): Long {
14+ var value = 0L
15+ var factor = 1
16+ var current = oasisHistory
17+
18+ while (current.any { it != 0L }) {
19+ value + = current.last()
20+
21+ current = current.windowed(2 ).map { (a, b) -> b - a }
22+ }
23+
24+ return value
25+ }
26+
27+ private fun convertInput (): List <List <Long >> =
28+ getResourceAsText(filename)
29+ .map { row ->
30+ row
31+ .split(" " )
32+ .stream()
33+ .map { element -> element.toLong() }
34+ .toList()
35+ }
36+
1037 private fun getResourceAsText (path : String ): List <String > =
1138 this .javaClass.classLoader.getResourceAsStream(path)!! .bufferedReader().readLines()
1239}
Original file line number Diff line number Diff line change @@ -27,10 +27,10 @@ class Day09Test {
2727 @JvmStatic
2828 private fun getDataForTestSolvePart1 (): Stream <Arguments > =
2929 Stream .of(
30- Arguments .of(" part1sample1.txt" , 0L ),
31- Arguments .of(" part1sample2.txt" , 0L ),
32- Arguments .of(" part1sample3.txt" , 0L ),
33- Arguments .of(" part1sample4.txt" , 0L )
30+ Arguments .of(" part1sample1.txt" , 18L ),
31+ Arguments .of(" part1sample2.txt" , 28L ),
32+ Arguments .of(" part1sample3.txt" , 68L ),
33+ Arguments .of(" part1sample4.txt" , 114L )
3434 )
3535
3636 @JvmStatic
You can’t perform that action at this time.
0 commit comments