day00: Add template

main
Elis Hirwing 10 months ago
parent 4d9e5cca8a
commit 74b642837c
Signed by: etu
GPG Key ID: D57EFA625C9A925F
  1. 1
      day00/example.txt
  2. 1
      day00/input.txt
  3. 22
      day00/solve.php
  4. 23
      lib/functions.php

@ -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
);

@ -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,
);
}
Loading…
Cancel
Save