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