adventofcode/2023/02/Part1.pm

26 lines
429 B
Perl
Raw Normal View History

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