Minor tidying.

Change-Id: I81f04b30668c9d4e081a21c941b30c5989ffcdb7
This commit is contained in:
Chris Hodges 2024-12-03 10:57:11 +01:00
parent 7695a005c9
commit b770db22c6

View File

@ -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<String>): Int { fun part1(input: List<String>): 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<String>): Int { fun part2(input: List<String>): Int {
val unp = input.joinToString("") return "mul\\((\\d+),(\\d+)\\)".toRegex()
val proc = unp.replace("(don't\\(\\).*?)+do\\(\\)".toRegex(), "") .findAll(input.joinToString("").replace("(don't\\(\\).*?)+do\\(\\)".toRegex(), ""))
return "mul\\(([0-9]+),([0-9]+)\\)".toRegex().findAll(proc).map { it.groupValues[1].toInt() * it.groupValues[2].toInt() }.sum() .sumOf { it.groupValues[1].toInt() * it.groupValues[2].toInt() }
} }
// test if implementation meets criteria from the description, like: // test if implementation meets criteria from the description, like: