1
0

ProjectEuler

This commit is contained in:
2020-01-17 00:25:29 +01:00
parent c5bc008db1
commit b5f8543da2
14 changed files with 169 additions and 116 deletions

View File

@@ -1,11 +1,18 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/blog.php');
require_once (__DIR__ . '/../internals/euler.php');
require_once (__DIR__ . '/../extern/Parsedown.php');
require_once (__DIR__ . '/../internals/website.php');
$problems = Euler::listAll();
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
global $FRAGMENT_PARAM;
/** @var array $parameter */
$parameter = $FRAGMENT_PARAM;
?>
<?php
$post = $parameter['blogpost'];
$problems = $SITE->modules->Euler()->listAll();
?>
<div class="boxedcontent blogcontent_euler base_markdown">

View File

@@ -1,18 +1,23 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/blog.php');
require_once (__DIR__ . '/../internals/euler.php');
require_once (__DIR__ . '/../internals/ParsedownCustom.php');
require_once (__DIR__ . '/../internals/website.php');
$subview = $OPTIONS['subview'];
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
$euler = Euler::listAll();
$problem = Euler::getEulerProblemFromStrIdent($subview);
global $FRAGMENT_PARAM;
/** @var array $parameter */
$parameter = $FRAGMENT_PARAM;
?>
if ($problem === NULL) httpError(404, 'Project Euler entry not found');
<?php
$post = $parameter['blogpost'];
$subview = $parameter['subview'];
$pd = new ParsedownCustom();
$euler = $SITE->modules->Euler()->listAll();
$problem = $SITE->modules->Euler()->getEulerProblemFromStrIdent($subview);
if ($problem === NULL) { $FRAME_OPTIONS->forceResult(404, 'Project Euler entry not found'); return; }
$arr = [];
$max = 0;
@@ -42,28 +47,19 @@ $max = ceil($max / 20) * 20;
<div class="bce_header"><h1><a href="<?php echo $problem['url_euler']; ?>">Problem <?php echo $problem['number3']; ?></a>: <?php echo htmlspecialchars($problem['title']); ?></h1></div>
<b>Description:</b>
<div class="bce_description"><?php echo $pd->text(file_get_contents($problem['file_description'])); ?></div>
<div class="bce_description"><?php echo $SITE->renderMarkdown(file_get_contents($problem['file_description'])); ?></div>
<br/>
<b>Solution:</b>
<?php
global $PARAM_BEFUNGE93RUNNER;
$PARAM_BEFUNGE93RUNNER =
[
'code' => file_get_contents($problem['file_code']),
'url' => $problem['url_raw'],
'interactive' => !$problem['abbreviated'],
'speed' => $problem['steps'] < 15000 ? 1 : ($problem['steps'] < 500000 ? 2 : 3),
'editable' => false,
];
echo require (__DIR__ . '/../fragments/widget_befunge93.php');
echo $SITE->fragments->WidgetBefunge93(file_get_contents($problem['file_code']), $problem['url_raw'], !$problem['abbreviated'], $problem['steps'] < 15000 ? 1 : ($problem['steps'] < 500000 ? 2 : 3), false);
if ($problem['abbreviated']) echo '<i>This program is too big to display/execute here, click [download] to get the full program. </i><br/>';
?>
<br/>
<b>Explanation:</b>
<div class="bce_explanation"><?php echo $pd->text(file_get_contents($problem['file_explanation'])); ?></div>
<div class="bce_explanation"><?php echo $SITE->renderMarkdown(file_get_contents($problem['file_explanation'])); ?></div>
<br/>
<table class="notable">

View File

@@ -22,7 +22,7 @@ $year = intval(end($years));
</div>
<div class="index_pnl_content">
<?php $SITE->fragments->PanelAdventOfCodeCalendar($year, true, true, true); ?>
<?php echo $SITE->fragments->PanelAdventOfCodeCalendar($year, true, true, true); ?>
</div>

View File

@@ -1,15 +1,23 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/website.php');
global $PARAM_BEFUNGE93RUNNER;
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
$code = $PARAM_BEFUNGE93RUNNER['code'];
$url = $PARAM_BEFUNGE93RUNNER['url'];
$interactive = $PARAM_BEFUNGE93RUNNER['interactive'];
$initspeed = $PARAM_BEFUNGE93RUNNER['speed'];
$editable = $PARAM_BEFUNGE93RUNNER['editable'];
global $FRAGMENT_PARAM;
/** @var array $parameter */
$parameter = $FRAGMENT_PARAM;
function fmtBef($str) {
$code = $parameter['code'];
$url = $parameter['url'];
$interactive = $parameter['interactive'];
$initspeed = $parameter['speed'];
$editable = $parameter['editable'];
function fmtBef($str)
{
$str = htmlspecialchars($str);
$str = str_replace("\r", "", $str);
$str = join("\n", array_map(function($p){return rtrim($p);}, explode("\n", $str)));
@@ -23,7 +31,8 @@ function fmtBef($str) {
$result = '';
if ($interactive) {
if ($interactive)
{
$speed_attr = '';
if (isset($initspeed) && $initspeed != NULL && $initspeed>0) $speed_attr = ' data-b93rnr_initialspeed="'.$initspeed.'" ';
$code_attr = '';
@@ -58,7 +67,7 @@ if ($interactive) {
$result .= ' </div>' . "\n";
$result .= '</div>' . "\n";
includeAdditionalScript("/data/javascript/blogpost_bef93runner.js");
$FRAME_OPTIONS->addScript("/data/javascript/blogpost_bef93runner.js", false);
}
else
{
@@ -72,4 +81,4 @@ else
$result .= '</div>' . "\n";
}
return $result;
echo $result;

View File

@@ -1,15 +1,25 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/website.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
global $FRAGMENT_PARAM;
/** @var array $parameter */
$parameter = $FRAGMENT_PARAM;
$codeLeft = $parameter['code_left'];
$codeRight = $parameter['code_right'];
global $PARAM_CODE_LEFT;
global $PARAM_CODE_RIGHT;
$result = '';
$result .= '<div class="bfjoust_runner_owner">' . "\n";
$result .= ' <div class="hsplit">' . "\n";
$result .= ' <textarea class="hsplit_1 source" id="source_1">' . htmlspecialchars($PARAM_CODE_LEFT) . '</textarea>' . "\n";
$result .= ' <textarea class="hsplit_2 source" id="source_2">' . htmlspecialchars($PARAM_CODE_RIGHT) . '</textarea>' . "\n";
$result .= ' <textarea class="hsplit_1 source" id="source_1">' . htmlspecialchars($codeLeft) . '</textarea>' . "\n";
$result .= ' <textarea class="hsplit_2 source" id="source_2">' . htmlspecialchars($codeRight) . '</textarea>' . "\n";
$result .= ' </div>' . "\n";
$result .= ' <div id="commandpanel">' . "\n";
@@ -35,6 +45,6 @@ $result .= '</div>' . "\n";
$result .= '' . "\n";
includeAdditionalScript("/data/javascript/blogpost_BFJoustBot_script.js");
$FRAME_OPTIONS->addScript('/data/javascript/blogpost_BFJoustBot_script.js', false);
return $result;
echo $result;