add preset for a perl day

main
Yanick Champoux 2023-12-01 13:38:44 -05:00
parent 679dbbe180
commit a163421f2c
11 changed files with 146 additions and 0 deletions

1
2023/preset/day/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

19
2023/preset/day/README.md Normal file
View File

@ -0,0 +1,19 @@
<p align="center">
<br />
<a href="https://preset.dev">
<img width="100" src="https://raw.githubusercontent.com/preset/preset/main/.github/assets/logo.svg" alt="Logo of Preset">
</a>
<br />
</p>
<h2 align="center">day</h2>
<pre><div align="center">npx @preset/cli apply username//home/yanick/work/javascript/adventofcode/2023/preset/day</div></pre>
<br />
<div align="center">
This preset was made by Yanick Champoux.
<br />
<br />
<a href="https://preset.dev">Learn more</a>
</div>

View File

@ -0,0 +1,6 @@
{
"private": true,
"author": "Yanick Champoux <yanick@babyl.ca>",
"license": "MIT",
"preset": "preset.ts"
}

14
2023/preset/day/preset.ts Normal file
View File

@ -0,0 +1,14 @@
export default definePreset({
name: 'day',
options: {
perl: true,
},
handler: async(context) => {
if( context.options.perl ) {
await extractTemplates({
from: 'perl', whenConflict: 'skip'
})
}
// ...
},
})

View File

View File

@ -0,0 +1,11 @@
use 5.38.0;
package Part1;
use List::AllUtils qw/ /;
sub solution_1 ($input) {
...;
}
1;

View File

@ -0,0 +1,14 @@
use 5.38.0;
package Part2;
use Part1;
use List::AllUtils qw/ /;
sub solution_2 ($input) {
...;
}
1;

View File

@ -0,0 +1,41 @@
use 5.38.0;
use Benchmark ':hireswallclock';
use Path::Tiny;
use JSON qw/ to_json /;
use DateTime;
use Part1;
use Part2;
my $day = path('.')->absolute->basename =~ s/^0//r;
my $year = path('.')->absolute->dir->basename;
my @parts = (
{ part => 1, sub => \&Part1::solution_1, expected => 'TODO' },
{ part => 2, sub => \&Part2::solution_2, expected => 'TODO' },
);
my $input = path('./input')->slurp;
for my $part (@parts) {
my $res = Benchmark::countit(
10,
sub {
$part->{sub}->($input) == $part->{expected} or die;
}
);
my $result = {
day => $day,
year => $year,
#variant => '',
language => 'perl',
part => $part->{part},
time => $res->cpu_a / $res->iters,
timestamp => DateTime->now->iso8601,
};
say to_json $result;
}

View File

@ -0,0 +1,11 @@
use 5.38.0;
use Test2::V0;
use Path::Tiny;
use Part1;
my $input = path('input')->slurp;
is Part1::solution_1($input) => 'TODO';

View File

@ -0,0 +1,11 @@
use 5.38.0;
use Test2::V0;
use Path::Tiny;
use Part2;
my $input = path('input')->slurp;
is Part2::solution_2($input) => 'TODO';

View File

@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "esnext",
"baseUrl": ".",
"target": "es2016",
"lib": ["esnext"],
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"types": ["node", "@preset/core/globals"]
},
"include": [
"./*.ts",
"./src/**/*.ts"
],
"exclude": ["templates", "node_modules"]
}