Yay, day 3 with Regexp magic.
Day 3
open(FH, '<', $ARGV[0]) or die $!;
my $sum = 0;
my $sum2 = 0;
my $enabled = 1;
while (<FH>) {
while ($_ =~ /(?:mul\((\d{1,3}),(\d{1,3})\)|(do)\(\)|(don\'t)\(\))/g) {
$enabled = 1 if $3;
$enabled = 0 if $4;
$sum += $1 * $2 if $1 && $2;
$sum2 += $1 * $2 if $enabled && $1 && $2;
}
}
close(FH);
print "Part 1: $sum\n";
print "Part 2: $sum2\n";
If this turns out to be another case of "research" where they told the model exactly what to do beforehand and then go all surprised Pikachu when it does, I'm gonna be shocked ...
... because it's been a while since they've tried that.