Bugfix for an edge case that wasn't in the input, gladly.

Change-Id: I7b1123e8f65d138dab777ea8383852f85402d59a
This commit is contained in:
Chris Hodges 2024-12-03 11:20:38 +01:00
parent b770db22c6
commit 64ba775ca6

View File

@ -22,7 +22,7 @@ fun main() {
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5)) xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
""" """
val inlineTestInput2 = """ val inlineTestInput2 = """
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5) xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)don't()mul(10,10)
""" """
fun part1(input: List<String>): Int { fun part1(input: List<String>): Int {
@ -32,7 +32,7 @@ xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)
fun part2(input: List<String>): Int { fun part2(input: List<String>): Int {
return "mul\\((\\d+),(\\d+)\\)".toRegex() return "mul\\((\\d+),(\\d+)\\)".toRegex()
.findAll(input.joinToString("").replace("(don't\\(\\).*?)+do\\(\\)".toRegex(), "")) .findAll((input.joinToString("") + "do()").replace("(don't\\(\\).*?)+(do\\(\\)|$)".toRegex(), ""))
.sumOf { it.groupValues[1].toInt() * it.groupValues[2].toInt() } .sumOf { it.groupValues[1].toInt() * it.groupValues[2].toInt() }
} }