Skip to content

Commit

Permalink
Day03: Minor simplification
Browse files Browse the repository at this point in the history
While neat, it does not make sense to do all this list allocation just to get two regexp groups in a neat way.
  • Loading branch information
julemand101 committed Dec 3, 2024
1 parent edbe515 commit a142c4c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/day03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ int solveA(Iterable<String> input) {
var sum = 0;

for (final match in input.expand(regExp.allMatches)) {
final [arg1!, arg2!] = match.groups([1, 2]);
sum += int.parse(arg1) * int.parse(arg2);
sum += int.parse(match[1]!) * int.parse(match[2]!);
}

return sum;
Expand All @@ -24,8 +23,7 @@ int solveB(Iterable<String> input) {
} else if (match[0] == "don't()") {
mulEnabled = false;
} else if (mulEnabled) {
final [arg1!, arg2!] = match.groups([1, 2]);
sum += int.parse(arg1) * int.parse(arg2);
sum += int.parse(match[1]!) * int.parse(match[2]!);
}
}

Expand Down

0 comments on commit a142c4c

Please sign in to comment.