part 2
This commit is contained in:
parent
462dfc9c7f
commit
5fedf5b0ac
@ -20,7 +20,6 @@ sub race_solution($time,$distance) {
|
||||
$min = int($min)+1;
|
||||
$max = ($max == int $max)?$max-1:int $max;
|
||||
|
||||
warn "$min - $max";
|
||||
return $max-$min+1;
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,14 @@ package Part2;
|
||||
|
||||
use Part1;
|
||||
|
||||
use List::AllUtils qw/ /;
|
||||
use List::AllUtils qw/ product /;
|
||||
|
||||
sub parse_file($input) {
|
||||
map { join '', /(\d+)/g } split "\n", $input;
|
||||
}
|
||||
|
||||
sub solution_2 ($input) {
|
||||
...;
|
||||
Part1::race_solution(parse_file($input));
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -4,6 +4,7 @@ use Benchmark ':hireswallclock';
|
||||
use Path::Tiny;
|
||||
use JSON qw/ to_json /;
|
||||
use DateTime;
|
||||
use File::Serialize;
|
||||
|
||||
use Part1;
|
||||
use Part2;
|
||||
@ -11,9 +12,11 @@ use Part2;
|
||||
my $day = path('.')->absolute->basename =~ s/^0//r;
|
||||
my $year = path('.')->absolute->parent->basename;
|
||||
|
||||
my $solutions = deserialize_file('solutions.yml');
|
||||
|
||||
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,
|
||||
persec => $res->iters/$res->cpu_a,
|
||||
timestamp => DateTime->now->iso8601,
|
||||
};
|
||||
say to_json $result;
|
||||
|
@ -3,11 +3,13 @@ use 5.38.0;
|
||||
use Test2::V0;
|
||||
|
||||
use Path::Tiny;
|
||||
use File::Serialize;
|
||||
|
||||
use Part1;
|
||||
|
||||
my $input = path('input')->slurp;
|
||||
my $example = path('example')->slurp;
|
||||
my $solutions = deserialize_file('solutions.yml');
|
||||
|
||||
is [ map { Part1::race_solution(@$_)} Part1::parse_file($example)]
|
||||
=> [4,8,9];
|
||||
@ -15,6 +17,6 @@ is [ map { Part1::race_solution(@$_)} Part1::parse_file($example)]
|
||||
is Part1::solution_1($example) => 288;
|
||||
|
||||
cmp_ok Part1::solution_1($input), '<' ,230202;
|
||||
is Part1::solution_1($input) => 'TODO';
|
||||
is Part1::solution_1($input) => $solutions->{1};
|
||||
|
||||
done_testing;
|
||||
|
@ -3,11 +3,15 @@ use 5.38.0;
|
||||
use Test2::V0;
|
||||
|
||||
use Path::Tiny;
|
||||
use File::Serialize;
|
||||
|
||||
use Part2;
|
||||
|
||||
my $input = path('input')->slurp;
|
||||
my $example = path('example')->slurp;
|
||||
my $solutions = deserialize_file('solutions.yml');
|
||||
|
||||
is Part2::solution_2($input) => 'TODO';
|
||||
is Part2::solution_2($example) => 71503;
|
||||
is Part2::solution_2($input) => $solutions->{2};
|
||||
|
||||
done_testing;
|
||||
|
@ -1,2 +1,2 @@
|
||||
1: 211904
|
||||
2: TODO
|
||||
2: 43364472
|
||||
|
@ -12,3 +12,6 @@
|
||||
{"day":4,"year":2023,"language":"javascript","part":"2","timestamp":"2023-12-04T15:22:09.052Z","time":0.002291685911610818,"persec":436.3599719025647}
|
||||
{"timestamp":"2023-12-05T23:24:26","persec":1139.15547024952,"year":"2023","day":"5","part":1,"language":"perl","time":0.000877843302443134}
|
||||
{"timestamp":"2023-12-05T23:24:38","persec":79.2380952380952,"year":"2023","day":"5","part":2,"time":0.0126201923076923,"language":"perl"}
|
||||
{"year":"2023","part":1,"day":"6","language":"perl","time":1.43016642439049e-05,"timestamp":"2023-12-06T15:43:00","persec":69921.9323671498}
|
||||
{"year":"2023","part":2,"language":"perl","day":"6","time":7.07875059716474e-06,"timestamp":"2023-12-06T15:43:13","persec":141267.867298578}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user