part 2
This commit is contained in:
parent
c446579923
commit
66b259d3a2
@ -9,12 +9,18 @@ use List::AllUtils qw/ all sum /;
|
||||
sub predict(@entries) {
|
||||
my $sum = 0;
|
||||
|
||||
my @first = ();
|
||||
|
||||
until( all { !$_ } @entries ) {
|
||||
$sum = $entries[0]-$sum;
|
||||
push @first, $entries[0];
|
||||
@entries = map { $entries[$_]-$entries[$_-1] } 1..$#entries;
|
||||
}
|
||||
|
||||
return -$sum;
|
||||
while(@first) {
|
||||
$sum = pop( @first ) - $sum;
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
sub solution_2 ($input) {
|
||||
|
@ -36,6 +36,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;
|
||||
|
@ -12,6 +12,6 @@ is Part1::predict(qw/0 3 6 9 12 15/) => 18;
|
||||
is Part1::predict(qw/1 3 6 10 15 21/) => 28;
|
||||
is Part1::predict(qw/10 13 16 21 30 45/) => 68;
|
||||
|
||||
is Part1::solution_1($input) => 'TODO';
|
||||
is Part1::solution_1($input) => 1884768153;
|
||||
|
||||
done_testing;
|
||||
|
@ -19,6 +19,6 @@ is Part2::solution_2(<<END) => 2;
|
||||
END
|
||||
|
||||
isnt Part2::solution_2($input) => -59;
|
||||
is Part2::solution_2($input) => 'TODO';
|
||||
is Part2::solution_2($input) => 1031;
|
||||
|
||||
done_testing;
|
||||
|
@ -1,2 +1,2 @@
|
||||
1: 1884768153
|
||||
2: TODO
|
||||
2: 1031
|
||||
|
@ -16,3 +16,5 @@
|
||||
{"year":"2023","part":2,"language":"perl","day":"6","time":7.07875059716474e-06,"timestamp":"2023-12-06T15:43:13","persec":141267.867298578}
|
||||
{"language":"perl","persec":85.2380952380952,"year":"2023","timestamp":"2023-12-07T16:08:30","time":0.011731843575419,"part":1,"day":"7"}
|
||||
{"day":"7","part":2,"persec":85.2380952380952,"year":"2023","timestamp":"2023-12-07T16:08:43","time":0.011731843575419,"language":"perl"}
|
||||
{"persec":113.488372093023,"timestamp":"2023-12-09T17:57:35","language":"perl","year":"2023","time":0.00881147540983607,"day":"9","part":1}
|
||||
{"persec":109.783631232361,"timestamp":"2023-12-09T17:57:47","language":"perl","time":0.00910882604970008,"day":"9","part":2,"year":"2023"}
|
||||
|
Loading…
Reference in New Issue
Block a user