Skip to content

Commit 6d2496c

Browse files
committed
Solved day06 part 2
1 parent 88f322e commit 6d2496c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-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.5.3'
7+
version '0.5.4'
88

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

day06/src/main/kotlin/de/havox_design/aoc2023/day06/Day06.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.havox_design.aoc2023.day06
22

3+
import kotlin.text.StringBuilder
4+
35
class 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

Comments
 (0)