diff --git a/src/aoc2024/Day03.kt b/src/aoc2024/Day03.kt index 2540a39..4035dee 100644 --- a/src/aoc2024/Day03.kt +++ b/src/aoc2024/Day03.kt @@ -26,13 +26,14 @@ xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5) """ fun part1(input: List): Int { - return "mul\\(([0-9]+),([0-9]+)\\)".toRegex().findAll(input.joinToString("")).map { it.groupValues[1].toInt() * it.groupValues[2].toInt() }.sum() + return "mul\\((\\d+),(\\d+)\\)".toRegex().findAll(input.joinToString("")) + .sumOf { it.groupValues[1].toInt() * it.groupValues[2].toInt() } } fun part2(input: List): Int { - val unp = input.joinToString("") - val proc = unp.replace("(don't\\(\\).*?)+do\\(\\)".toRegex(), "") - return "mul\\(([0-9]+),([0-9]+)\\)".toRegex().findAll(proc).map { it.groupValues[1].toInt() * it.groupValues[2].toInt() }.sum() + return "mul\\((\\d+),(\\d+)\\)".toRegex() + .findAll(input.joinToString("").replace("(don't\\(\\).*?)+do\\(\\)".toRegex(), "")) + .sumOf { it.groupValues[1].toInt() * it.groupValues[2].toInt() } } // test if implementation meets criteria from the description, like: