Advertisement
hrabrica

AoC | Day 6 | Part 2

Dec 5th, 2023
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.77 KB | Source Code | 0 0
  1. package year_2023.day_6
  2.  
  3. fun partTwo() {
  4.     println("[2023] Day six, part two...")
  5.  
  6.     val input = input()
  7.     val time = input.split("\n")[0]
  8.         .substringAfter(":")
  9.         .split(" ")
  10.         .filter { it.isNotBlank() }
  11.         .joinToString("")
  12.         .toLong()
  13.  
  14.     val distance = input.split("\n")[1]
  15.         .substringAfter(":")
  16.         .split(" ")
  17.         .filter { it.isNotBlank() }
  18.         .joinToString("")
  19.         .toLong()
  20.  
  21.  
  22.     var validCounter = 0
  23.     (1..time).forEach { timeHolding ->
  24.         val speed = timeHolding
  25.         val remainingTime = time - timeHolding
  26.         val totalDistance = speed * remainingTime
  27.  
  28.         if (totalDistance > distance) {
  29.             validCounter++
  30.         }
  31.     }
  32.  
  33.     println(validCounter)
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement