adventofcode/2023/02/Part1.pm

26 lines
429 B
Perl

use 5.38.0;
package Part1;
use List::AllUtils qw/ max sum /;
sub parse_line($line) {
my %data;
$line =~ /Game (\d+):/;
$data{game} = $1;
$data{$_} = max $line =~ /(\d+) $_/g for qw/ red green blue /;
return \%data;
}
sub solution_1 ($input) {
sum
map { $_->{game} }
grep { $_->{red} <= 12 and $_->{blue} <= 14 and $_->{green} <= 13 }
map { parse_line($_)}
split "\n", $input;
}
1;