From 64ba775ca611abbf6318008fbd51b4eadc1f10ab Mon Sep 17 00:00:00 2001 From: Chris Hodges Date: Tue, 3 Dec 2024 11:20:38 +0100 Subject: [PATCH] Bugfix for an edge case that wasn't in the input, gladly. Change-Id: I7b1123e8f65d138dab777ea8383852f85402d59a --- src/aoc2024/Day03.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aoc2024/Day03.kt b/src/aoc2024/Day03.kt index 4035dee..99953f5 100644 --- a/src/aoc2024/Day03.kt +++ b/src/aoc2024/Day03.kt @@ -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)) """ 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): 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): Int { 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() } }