From a163421f2cc1c6d799f4df3e490372ee15ea6b19 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 1 Dec 2023 13:38:44 -0500 Subject: [PATCH] add preset for a perl day --- 2023/preset/day/.gitignore | 1 + 2023/preset/day/README.md | 19 ++++++++++ 2023/preset/day/package.json | 6 +++ 2023/preset/day/preset.ts | 14 +++++++ 2023/preset/day/templates/.gitkeep | 0 2023/preset/day/templates/perl/Part1.pm | 11 ++++++ 2023/preset/day/templates/perl/Part2.pm | 14 +++++++ 2023/preset/day/templates/perl/benchmark.pl | 41 +++++++++++++++++++++ 2023/preset/day/templates/perl/part1.t | 11 ++++++ 2023/preset/day/templates/perl/part2.t | 11 ++++++ 2023/preset/day/tsconfig.json | 18 +++++++++ 11 files changed, 146 insertions(+) create mode 100644 2023/preset/day/.gitignore create mode 100644 2023/preset/day/README.md create mode 100644 2023/preset/day/package.json create mode 100644 2023/preset/day/preset.ts create mode 100644 2023/preset/day/templates/.gitkeep create mode 100644 2023/preset/day/templates/perl/Part1.pm create mode 100644 2023/preset/day/templates/perl/Part2.pm create mode 100644 2023/preset/day/templates/perl/benchmark.pl create mode 100644 2023/preset/day/templates/perl/part1.t create mode 100644 2023/preset/day/templates/perl/part2.t create mode 100644 2023/preset/day/tsconfig.json diff --git a/2023/preset/day/.gitignore b/2023/preset/day/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/2023/preset/day/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/2023/preset/day/README.md b/2023/preset/day/README.md new file mode 100644 index 0000000..c513b01 --- /dev/null +++ b/2023/preset/day/README.md @@ -0,0 +1,19 @@ +

+
+ + Logo of Preset + +
+

+ +

day

+
npx @preset/cli apply username//home/yanick/work/javascript/adventofcode/2023/preset/day
+ +
+ +
+ This preset was made by Yanick Champoux. +
+
+ Learn more +
diff --git a/2023/preset/day/package.json b/2023/preset/day/package.json new file mode 100644 index 0000000..850e04c --- /dev/null +++ b/2023/preset/day/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "author": "Yanick Champoux ", + "license": "MIT", + "preset": "preset.ts" +} diff --git a/2023/preset/day/preset.ts b/2023/preset/day/preset.ts new file mode 100644 index 0000000..163677f --- /dev/null +++ b/2023/preset/day/preset.ts @@ -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' + }) + } + // ... + }, +}) diff --git a/2023/preset/day/templates/.gitkeep b/2023/preset/day/templates/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/2023/preset/day/templates/perl/Part1.pm b/2023/preset/day/templates/perl/Part1.pm new file mode 100644 index 0000000..c9b4e65 --- /dev/null +++ b/2023/preset/day/templates/perl/Part1.pm @@ -0,0 +1,11 @@ +use 5.38.0; + +package Part1; + +use List::AllUtils qw/ /; + +sub solution_1 ($input) { + ...; +} + +1; diff --git a/2023/preset/day/templates/perl/Part2.pm b/2023/preset/day/templates/perl/Part2.pm new file mode 100644 index 0000000..c907947 --- /dev/null +++ b/2023/preset/day/templates/perl/Part2.pm @@ -0,0 +1,14 @@ +use 5.38.0; + +package Part2; + +use Part1; + +use List::AllUtils qw/ /; + + +sub solution_2 ($input) { + ...; +} + +1; diff --git a/2023/preset/day/templates/perl/benchmark.pl b/2023/preset/day/templates/perl/benchmark.pl new file mode 100644 index 0000000..a01b63b --- /dev/null +++ b/2023/preset/day/templates/perl/benchmark.pl @@ -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; +} + diff --git a/2023/preset/day/templates/perl/part1.t b/2023/preset/day/templates/perl/part1.t new file mode 100644 index 0000000..d09f96c --- /dev/null +++ b/2023/preset/day/templates/perl/part1.t @@ -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'; diff --git a/2023/preset/day/templates/perl/part2.t b/2023/preset/day/templates/perl/part2.t new file mode 100644 index 0000000..41be8ed --- /dev/null +++ b/2023/preset/day/templates/perl/part2.t @@ -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'; diff --git a/2023/preset/day/tsconfig.json b/2023/preset/day/tsconfig.json new file mode 100644 index 0000000..5dcab8a --- /dev/null +++ b/2023/preset/day/tsconfig.json @@ -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"] +}