Skip to content

Commit f25394c

Browse files
committed
Add 2023 Day 6 Part 2 solution
1 parent a5e475b commit f25394c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

adventofcode2023/Day06.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ object Day06 {
1111
println(times.indices.map {
1212
var chargeTime = 1
1313
while (chargeTime * (times[it] - chargeTime) < distances[it]) chargeTime++
14-
(times[it] + 1) - 2 * chargeTime
14+
times[it] + 1 - 2 * chargeTime
1515
}.reduce { acc, x -> acc * x })
1616
}
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+
}
1726
}
1827

1928
fun main() {
2029
val inputs = File("resources/adventofcode2023/Day06.txt").readLines()
2130
Day06.part1(inputs)
31+
Day06.part2(inputs)
2232
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy