This commit is contained in:
Yanick Champoux 2023-12-02 11:41:31 -05:00
parent 3363c98943
commit b29e4a9a60
5 changed files with 29 additions and 10 deletions

View File

@ -4,11 +4,14 @@ package Part2;
use Part1;
use List::AllUtils qw/ /;
use List::AllUtils qw/ min product sum /;
sub solution_2 ($input) {
...;
sum
map { product $_->@{qw/ red blue green /}}
map { Part1::aggregate_entries($_) }
map { Part1::parse_line($_)}
split "\n", $input;
}
1;

View File

@ -4,16 +4,19 @@ use Benchmark ':hireswallclock';
use Path::Tiny;
use JSON qw/ to_json /;
use DateTime;
use File::Serialize;
use Part1;
use Part2;
my $solutions = deserialize_file('solutions.yml');
my $day = path('.')->absolute->basename =~ s/^0//r;
my $year = path('.')->absolute->dir->basename;
my $year = path('.')->absolute->parent->basename;
my @parts = (
{ part => 1, sub => \&Part1::solution_1, expected => 'TODO' },
{ part => 2, sub => \&Part2::solution_2, expected => 'TODO' },
{ part => 1, sub => \&Part1::solution_1, expected => $solutions->{1} },
{ part => 2, sub => \&Part2::solution_2, expected => $solutions->{2} },
);
my $input = path('./input')->slurp;
@ -34,6 +37,7 @@ for my $part (@parts) {
language => 'perl',
part => $part->{part},
time => $res->cpu_a / $res->iters,
parsec =>$res->iters/$res->cpu_a ,
timestamp => DateTime->now->iso8601,
};
say to_json $result;

View File

@ -6,6 +6,15 @@ use Path::Tiny;
use Part2;
is Part2::solution_2( <<'END' ) => 2286;
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
END
my $input = path('input')->slurp;
cmp_ok Part2::solution_2($input), ">", 1720;
is Part2::solution_2($input) => 'TODO';

View File

@ -1 +1,2 @@
1: 1853
2: 72706

View File

@ -1,4 +1,6 @@
{"language":"perl","time":0.00189813978688821,"part":1,"day":1,"year":2023,"timestamp":"2023-12-01T17:35:46"}
{"language":"perl","part":2,"time":0.00721379310344828,"day":1,"year":2023,"timestamp":"2023-12-01T17:35:58"}
{"day":1,"year":2023,"language":"javascript","part":"1","timestamp":"2023-12-01T20:55:40.986Z","time":0.0007267522645031297}
{"day":1,"year":2023,"language":"javascript","part":"2","timestamp":"2023-12-01T20:55:40.989Z","time":0.004363576172638605}
{"language":"perl","time":0.00189813978688821,"part":1,"day":1,"year":2023,"timestamp":"2023-12-01T17:35:46","persec":526.8315889628915}
{"language":"perl","part":2,"time":0.00721379310344828,"day":1,"year":2023,"timestamp":"2023-12-01T17:35:58","persec":138.62332695984696}
{"day":1,"year":2023,"language":"javascript","part":"1","timestamp":"2023-12-01T20:55:40.986Z","time":0.0007267522645031297,"persec":1375.9847046141451}
{"day":1,"year":2023,"language":"javascript","part":"2","timestamp":"2023-12-01T20:55:40.989Z","time":0.004363576172638605,"persec":229.1698277826353}
{"language":"perl","timestamp":"2023-12-02T16:40:42","part":1,"day":"2","parsec":297.067171239357,"year":"2023","time":0.00336624203821656}
{"language":"perl","timestamp":"2023-12-02T16:40:55","part":2,"day":"2","time":0.00338658146964856,"year":"2023","parsec":295.283018867925}