From 63a9e0dc7cf63d8040d02c8d3ada69144b7e4a30 Mon Sep 17 00:00:00 2001 From: TheCK Date: Tue, 3 Dec 2024 06:45:36 +0100 Subject: [PATCH] aoc 2024 day 3 refactor --- .../org/ck/adventofcode/year2024/Day03.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/adventofcode/src/main/java/org/ck/adventofcode/year2024/Day03.java b/adventofcode/src/main/java/org/ck/adventofcode/year2024/Day03.java index aaf9cbed..92787dbe 100644 --- a/adventofcode/src/main/java/org/ck/adventofcode/year2024/Day03.java +++ b/adventofcode/src/main/java/org/ck/adventofcode/year2024/Day03.java @@ -42,15 +42,16 @@ private void run(final Scanner in, final boolean enableDisable) { long sum = 0; while (matcher.find(index)) { - if (enableDisable && deactivationMatcher.find(index)) { - if (deactivationMatcher.start() < matcher.start()) { - if (activeMatcher.find(deactivationMatcher.start())) { - index = activeMatcher.end(); - continue; - } + if (enableDisable + && deactivationMatcher.find(index) + && deactivationMatcher.start() < matcher.start()) { - break; + if (activeMatcher.find(deactivationMatcher.start())) { + index = activeMatcher.end(); + continue; } + + break; } final long one = Long.parseLong(matcher.group("one")); @@ -70,7 +71,6 @@ private static String readInput(final Scanner in) { builder.append(in.nextLine()); } - final String input = builder.toString(); - return input; + return builder.toString(); } }