day00: Add template

main
Elis Hirwing 2021-12-04 09:14:30 +01:00
parent 4d9e5cca8a
commit 74b642837c
Signed by: etu
GPG Key ID: D57EFA625C9A925F
4 changed files with 47 additions and 0 deletions

1
day00/example.txt Normal file
View File

@ -0,0 +1 @@

1
day00/input.txt Normal file
View File

@ -0,0 +1 @@

22
day00/solve.php Normal file
View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
require_once(__DIR__.'/../lib/functions.php');
$entries = getLines(__DIR__.'/'.$argv[1].'.txt');
timedPrintf(
'[2021-12-00.1] DESCRIPTION: %d [Time: %ss]',
(function (array $entries) : int {
return 1;
}),
$entries
);
timedPrintf(
'[2021-12-00.2] DESCRIPTION: %d [Time: %ss]',
(function (array $entries) : int {
return 1;
}),
$entries
);

23
lib/functions.php Normal file
View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
function getLines(string $filename, bool $filter = true) : array
{
$fileContents = file_get_contents($filename);
$lines = explode(PHP_EOL, $fileContents);
return $filter ? array_filter($lines) : $lines;
}
function timedPrintf(string $format, callable $fn, array $args) : void
{
$timeBefore = microtime(true);
$result = $fn($args);
$timeAfter = microtime(true);
printf(
$format.PHP_EOL,
$result,
$timeAfter - $timeBefore,
);
}