Advertisement
hrabrica

AoC 2024 | Day 3 | Part 1

Dec 2nd, 2024
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.52 KB | None | 0 0
  1. fun partOne() {
  2.     println("[2024] Day three, part one...")
  3.     val input = input()
  4.     val regex = "mul\\(\\d+,\\d+\\)".toRegex()
  5.     val validMuls = regex.findAll(input)
  6.         .map {
  7.             val values = it.value
  8.                 .substringAfter("(")
  9.                 .substringBeforeLast(")")
  10.                 .split(",")
  11.                 .map { it.toLong() }
  12.  
  13.             values[0] to values[1]
  14.         }.toMutableList()
  15.  
  16.     val result = validMuls.sumOf { it.first * it.second }
  17.     println("Result: $result")
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement