File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,22 @@ object Day06 {
11
11
println (times.indices.map {
12
12
var chargeTime = 1
13
13
while (chargeTime * (times[it] - chargeTime) < distances[it]) chargeTime++
14
- ( times[it] + 1 ) - 2 * chargeTime
14
+ times[it] + 1 - 2 * chargeTime
15
15
}.reduce { acc, x -> acc * x })
16
16
}
17
+
18
+ fun part2 (inputs : List <String >) {
19
+ val (time, distance) = inputs.map { line ->
20
+ line.replace(" \\ s+" .toRegex(), " " ).split(" " ).drop(1 ).joinToString(" " ).toLong()
21
+ }
22
+ var chargeTime = 1
23
+ while (chargeTime * (time - chargeTime) < distance) chargeTime++
24
+ println (time + 1 - 2 * chargeTime)
25
+ }
17
26
}
18
27
19
28
fun main () {
20
29
val inputs = File (" resources/adventofcode2023/Day06.txt" ).readLines()
21
30
Day06 .part1(inputs)
31
+ Day06 .part2(inputs)
22
32
}
You can’t perform that action at this time.
0 commit comments