Minor tidying.
Change-Id: I81f04b30668c9d4e081a21c941b30c5989ffcdb7
This commit is contained in:
parent
7695a005c9
commit
b770db22c6
@ -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 {
|
||||
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 {
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user