Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package year_2023.day_6
- fun partTwo() {
- println("[2023] Day six, part two...")
- val input = input()
- val time = input.split("\n")[0]
- .substringAfter(":")
- .split(" ")
- .filter { it.isNotBlank() }
- .joinToString("")
- .toLong()
- val distance = input.split("\n")[1]
- .substringAfter(":")
- .split(" ")
- .filter { it.isNotBlank() }
- .joinToString("")
- .toLong()
- var validCounter = 0
- (1..time).forEach { timeHolding ->
- val speed = timeHolding
- val remainingTime = time - timeHolding
- val totalDistance = speed * remainingTime
- if (totalDistance > distance) {
- validCounter++
- }
- }
- println(validCounter)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement