1
0
This commit is contained in:
Mike Schwörer 2020-01-15 00:32:24 +01:00
parent f06948851c
commit e5dc57e2b5
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
4 changed files with 56 additions and 32 deletions

View File

@ -71,7 +71,7 @@ class AdventOfCode
return array_keys($this->staticData);
}
public static function readSingle($year, $a)
private static function readSingle($year, $a)
{
$yeardata = self::YEARS[$year];

View File

@ -19,7 +19,7 @@ class Books
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}
public static function readSingle($a)
private static function readSingle($a)
{
$a['imgfront_url'] = '/data/images/book_img/' . $a['id'] . '_front.png';
$a['imgfront_path'] = __DIR__ . '/../data/images/book_img/' . $a['id'] . '_front.png';

View File

@ -1,8 +1,25 @@
<?php
require_once 'website.php';
class Euler
{
public static function readSingle($a)
/** @var array */
private $staticData;
public function __construct()
{
$this->load();
}
private function load()
{
$all = require (__DIR__ . '/../statics/blog/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}
private static function readSingle($a)
{
$n3p = str_pad($a['number'], 3, '0', STR_PAD_LEFT);
$a['number3'] = $n3p;
@ -25,33 +42,7 @@ class Euler
return $a;
}
public static function listAll()
{
$all = require (__DIR__ . '/../statics/euler/__all.php');
return array_map('self::readSingle', $all);
}
public static function getEulerProblemFromStrIdent($ident)
{
$e = explode('-', $ident, 2); // problem-xxx
if (count($e)!==2) return null;
$i = intval($e[1], 10);
if ($i == 0) return null;
return self::getEulerProblem($i);
}
public static function getEulerProblem($num)
{
foreach (self::listAll() as $ep) {
if ($ep['number'] == $num) return $ep;
}
return null;
}
public static function rateTime($problem)
private static function rateTime($problem)
{
if ($problem['time'] < 100) // < 100ms
return 0;
@ -68,14 +59,40 @@ class Euler
return 4;
}
public static function checkConsistency()
public function listAll()
{
return $this->staticData;
}
public function getEulerProblemFromStrIdent($ident)
{
$e = explode('-', $ident, 2); // problem-xxx
if (count($e)!==2) return null;
$i = intval($e[1], 10);
if ($i == 0) return null;
return self::getEulerProblem($i);
}
public function getEulerProblem($num)
{
foreach (self::listAll() as $ep) {
if ($ep['number'] == $num) return $ep;
}
return null;
}
public function checkConsistency()
{
$warn = null;
$this->load();
$numbers = [];
$realname = [];
foreach (self::listAll() as $ep)
foreach ($this->staticData as $ep)
{
if (in_array($ep['number'], $numbers)) return ['result'=>'err', 'message' => 'Duplicate number ' . $ep['number']];
$numbers []= $ep['number'];

View File

@ -21,6 +21,7 @@ class Website
/** @var AdventOfCode|null */ private $adventOfCode = null;
/** @var Blog|null */ private $blog = null;
/** @var Books|null */ private $books = null;
/** @var Euler|null */ private $euler = null;
public function init()
{
@ -182,6 +183,12 @@ class Website
return $this->books;
}
public function Euler()
{
if ($this->euler === null) { require_once 'euler.php'; $this->euler = new Euler(); }
return $this->euler;
}
/**