adventofcode/2023/02/Part1.pm
2023-12-02 13:33:33 -05:00

26 lines
440 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;