-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunSolution.php
More file actions
55 lines (48 loc) · 1.21 KB
/
runSolution.php
File metadata and controls
55 lines (48 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
function validateYear(string $argv)
{
if (strlen($argv[1]) !== 4) {
return false;
}
return true;
}
function validateDay(string $argv)
{
return true;
}
function executeDay(string $year, string $day)
{
$solutionFile = implode(DIRECTORY_SEPARATOR, [__DIR__, $year, $day, 'solution.php']);
if (is_file($solutionFile)) {
echo "=== DAY {$day} SOLUTION ===\n";
exec("php {$solutionFile}", $output);
foreach ($output as $line) {
echo "{$line}\n";
}
return true;
}
return false;
}
$year = date('Y');
$day = date('d');
if (isset($argv[1]) && validateYear($argv[1])) {
$year = $argv[1];
}
if (isset($argv[2]) && validateDay($argv[2])) {
$day = str_pad($argv[2], 2, "0", STR_PAD_LEFT);
} else {
$day = null;
}
$yearDir = __DIR__ . DIRECTORY_SEPARATOR . $year;
if ($year && is_dir($yearDir) && !$day) {
$dayDirs = scandir($yearDir);
foreach ($dayDirs as $dayDir) {
$output = [];
executeDay($year, $dayDir);
}
} elseif ($year && is_dir($yearDir) && $day) {
if (!executeDay($year, $day)) {
echo "ERROR, could not find solution for year '{$year}' and day '{$day}'";
}
}