tidy
This commit is contained in:
parent
4c98ac6a61
commit
c1984999cf
@ -4,10 +4,10 @@ package Part1;
|
||||
|
||||
use List::AllUtils qw/ max sum /;
|
||||
|
||||
sub parse_line($line) {
|
||||
sub parse_line ($line) {
|
||||
my %data;
|
||||
$line =~ /Game (\d+):/;
|
||||
$data{game} = $1;
|
||||
$data{game} = $1;
|
||||
|
||||
$data{$_} = max $line =~ /(\d+) $_/g for qw/ red green blue /;
|
||||
|
||||
@ -16,10 +16,10 @@ sub parse_line($line) {
|
||||
|
||||
sub solution_1 ($input) {
|
||||
sum
|
||||
map { $_->{game} }
|
||||
grep { $_->{red} <= 12 and $_->{blue} <= 14 and $_->{green} <= 13 }
|
||||
map { parse_line($_)}
|
||||
split "\n", $input;
|
||||
map { $_->{game} }
|
||||
grep { $_->{red} <= 12 and $_->{blue} <= 14 and $_->{green} <= 13 }
|
||||
map { parse_line($_) }
|
||||
split "\n", $input;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -8,9 +8,9 @@ use List::AllUtils qw/ min product sum /;
|
||||
|
||||
sub solution_2 ($input) {
|
||||
sum
|
||||
map { product $_->@{qw/ red blue green /}}
|
||||
map { Part1::parse_line($_)}
|
||||
split "\n", $input;
|
||||
map { product $_->@{qw/ red blue green /} }
|
||||
map { Part1::parse_line($_) }
|
||||
split "\n", $input;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -6,10 +6,13 @@ use Path::Tiny;
|
||||
|
||||
use Part1;
|
||||
|
||||
|
||||
is Part1::parse_line("Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green") => +{ game => 1,
|
||||
blue => 6, red => 4, green => 2
|
||||
};
|
||||
is Part1::parse_line(
|
||||
"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green") => +{
|
||||
game => 1,
|
||||
blue => 6,
|
||||
red => 4,
|
||||
green => 2
|
||||
};
|
||||
|
||||
is Part1::solution_1( <<'END' ) => 8;
|
||||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
|
Loading…
Reference in New Issue
Block a user