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 18:32:51 +00:00
|
|
|
sub parse_line ($line) {
|
2023-12-02 16:17:13 +00:00
|
|
|
my %data;
|
2023-12-02 18:30:04 +00:00
|
|
|
$line =~ /Game (\d+):/;
|
2023-12-02 18:32:51 +00:00
|
|
|
$data{game} = $1;
|
2023-12-02 16:17:13 +00:00
|
|
|
|
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
|
2023-12-02 18:32:51 +00:00
|
|
|
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;
|