Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package year_2023.day_6
- fun partOne() {
- println("[2023] Day six, part one...")
- val times = input().split("\n")[0]
- .substringAfter(":")
- .split(" ")
- .filter { it.isNotBlank() }
- .map { it.trim().toInt() }
- val distances = input().split("\n")[1]
- .substringAfter(":")
- .split(" ")
- .filter { it.isNotBlank() }
- .map { it.trim().toInt() }
- val waysToBeatPerRound = mutableListOf<Int>()
- repeat(times.size) {
- val time = times[it]
- val distance = distances[it]
- var validCounter = 0
- (1..time).forEach { timeHolding ->
- val speed = timeHolding
- val remainingTime = time - timeHolding
- val totalDistance = speed * remainingTime
- if (totalDistance > distance) {
- validCounter++
- }
- }
- waysToBeatPerRound.add(validCounter)
- }
- val result = waysToBeatPerRound.reduce { acc, i -> acc * i }
- println(result)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement