11package de.havox_design.aoc2023.day06
22
3+ import kotlin.text.StringBuilder
4+
35class Day06 (private var filename : String ) {
46 private val DISTANCE_INDEX = 1
57 private val DISTANCE_PREFIX = " Distance: "
@@ -8,7 +10,8 @@ class Day06(private var filename: String) {
810 private val TIME_PREFIX = " Time: "
911
1012 fun solvePart1 (): Long {
11- val combinations = convertInput(getResourceAsText(filename)).map { game -> simulate(game.first, game.second) }
13+ val combinations = convertInput(getResourceAsText(filename))
14+ .map { game -> simulate(game.first, game.second) }
1215 var product = 1L
1316
1417 for (value in combinations) {
@@ -18,8 +21,24 @@ class Day06(private var filename: String) {
1821 return product
1922 }
2023
21- fun solvePart2 (): Long =
22- 71503L
24+ fun solvePart2 (): Long {
25+ val games = convertInput(getResourceAsText(filename))
26+ val game = fixInput(games)
27+
28+ return simulate(game.first, game.second).toLong()
29+ }
30+
31+ private fun fixInput (input : List <Pair <Long , Long >>): Pair <Long , Long > {
32+ var duration = StringBuilder ()
33+ var distance = StringBuilder ()
34+
35+ for (entry in input) {
36+ duration.append(entry.first)
37+ distance.append(entry.second)
38+ }
39+
40+ return Pair (duration.toString().toLong(), distance.toString().toLong())
41+ }
2342
2443 private fun convertInput (input : List <String >): List <Pair <Long , Long >> {
2544 val times = input[TIME_INDEX ]
0 commit comments