aoc_2024/day03.kts
Logiar 29a9f321cd
Some checks failed
Solve / example-action (push) Failing after 36s
Removing inputs.
2024-12-05 14:43:19 +01:00

31 lines
900 B
Kotlin
Executable File

#!/usr/bin/env kotlin
import java.io.File
import java.util.Scanner
val scanner = Scanner(System.`in`)
var partOneSum = 0
var partTwoSum = 0
var doState = true
while (scanner.hasNextLine()) {
val line = scanner.nextLine()
val regex = Regex("(mul\\((\\d+),(\\d+)\\))|(do\\(\\))|(don't\\(\\))")
val match = regex.findAll(line)
for (matchResult in match) {
if (matchResult.value == "don't()") {
doState = false
} else if (matchResult.value == "do()") {
doState = true
} else {
val (a, b, c) = matchResult.destructured
val factorOne = b.toInt()
val factorTwo = c.toInt()
partOneSum += factorOne * factorTwo
if (doState) {
partTwoSum += factorOne * factorTwo
}
}
}
}
println("Part One Sum: $partOneSum")
println("Part Two Sum: $partTwoSum")