#!/usr/bin/env kotlin 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")