1
0

ProjectEuler

This commit is contained in:
Mike Schwörer 2020-01-17 00:25:29 +01:00
parent c5bc008db1
commit b5f8543da2
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
14 changed files with 169 additions and 116 deletions

View File

@ -18,4 +18,4 @@ $linkheader = boolval($API_OPTIONS['linkheader']);
$ajax = boolval($API_OPTIONS['ajax']);
$frameid = strval($API_OPTIONS['frameid']);
$SITE->fragments->PanelAdventOfCodeCalendar($year, $shownav, $linkheader, $ajax, false, $frameid);
echo $SITE->fragments->PanelAdventOfCodeCalendar($year, $shownav, $linkheader, $ajax, false, $frameid);

View File

@ -1924,6 +1924,8 @@ html, body {
background-color: #BBBBBB;
text-align: left;
padding: 4px;
font-family: Consolas, Monaco, "Courier New", Menlo, monospace;
font-size: small;
overflow-x: auto;
white-space: nowrap;
width: 100%;

View File

@ -364,7 +364,7 @@ html,body{margin:0;padding:0;height:100%}
@media(min-width:851px){.ev_master{padding-bottom:80px}}
.ev_master .ev_code{color:#333;text-align:center;font-size:150pt;font-weight:500;font-family:Consolas,Monaco,"Courier New",Menlo,monospace}
.ev_master .ev_msg{color:#888;text-align:center;font-size:25pt}
.ev_master .ev_statusmore{color:#333;background-color:#bbb;text-align:left;padding:4px;overflow-x:auto;white-space:nowrap;width:100%}
.ev_master .ev_statusmore{color:#333;background-color:#bbb;text-align:left;padding:4px;font-family:Consolas,Monaco,"Courier New",Menlo,monospace;font-size:small;overflow-x:auto;white-space:nowrap;width:100%}
@media(max-width:767px){
.ev_master .ev_code{font-size:75pt}
.ev_master .ev_msg{font-size:15pt}

View File

@ -26,6 +26,8 @@
background-color: $LAYER1_BG_DARKER;
text-align: left;
padding: 4px;
font-family: $FONT_CODE;
font-size: small;
overflow-x: auto;
white-space: nowrap;

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;

View File

@ -2,89 +2,131 @@
class Fragments
{
public function PanelEuler()
private function evalFragment($name, $url, $params)
{
try
{
ob_start();
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_euler.php');
$FRAGMENT_PARAM = $params;
/** @noinspection PhpIncludeInspection */
include (__DIR__ . '/../fragments/' . $url);
}
return ob_get_contents();
}
finally
{
ob_end_clean();
}
}
public function PanelEuler()
{
return $this->evalFragment('PanelEuler', 'panel_euler.php', [ ]);
}
public function PanelPrograms()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_programs.php');
return $this->evalFragment('PanelPrograms', 'panel_programs.php', [ ]);
}
public function PanelBlog()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_blog.php');
return $this->evalFragment('PanelBlog', 'panel_blog.php', [ ]);
}
public function PanelBooks()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_books.php');
return $this->evalFragment('PanelBooks', 'panel_books.php', [ ]);
}
public function PanelAdventOfCode()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_aoc.php');
return $this->evalFragment('PanelAdventOfCode', 'panel_aoc.php', [ ]);
}
public function PanelAdventOfCodeCalendar(int $year, bool $shownav, bool $linkheader, bool $ajax, bool $frame=true, $frameid=null)
{
if ($frameid == null) $frameid = 'aoc_frame_' . getRandomToken(16);
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ 'year' => $year, 'nav'=>$shownav, 'linkheader'=>$linkheader, 'ajax'=>$ajax, 'frame'=>$frame, 'frameid'=>$frameid ];
include (__DIR__ . '/../fragments/panel_aoc_calendar.php');
return $this->evalFragment('PanelAdventOfCodeCalendar', 'panel_aoc_calendar.php',
[
'year' => $year,
'nav' => $shownav,
'linkheader' => $linkheader,
'ajax' => $ajax,
'frame' => $frame,
'frameid' => ($frameid == null) ? ('aoc_frame_' . getRandomToken(16)) : $frameid,
]);
}
public function BlogviewPlain(array $blogpost)
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ 'blogpost' => $blogpost ];
include (__DIR__ . '/../fragments/blogview_plain.php');
return $this->evalFragment('BlogviewPlain', 'blogview_plain.php',
[
'blogpost' => $blogpost,
]);
}
public function BlogviewMarkdown(array $blogpost)
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ 'blogpost' => $blogpost ];
include (__DIR__ . '/../fragments/blogview_markdown.php');
return $this->evalFragment('BlogviewMarkdown', 'blogview_markdown.php',
[
'blogpost' => $blogpost,
]);
}
public function BlogviewEulerList(array $blogpost)
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ 'blogpost' => $blogpost ];
include (__DIR__ . '/../fragments/blogview_euler_list.php');
return $this->evalFragment('BlogviewEulerList', 'blogview_euler_list.php',
[
'blogpost' => $blogpost,
]);
}
public function BlogviewEulerSingle(array $blogpost, string $subview)
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ 'blogpost' => $blogpost, 'subview' => $subview ];
include (__DIR__ . '/../fragments/blogview_euler_single.php');
return $this->evalFragment('BlogviewEulerSingle', 'blogview_euler_single.php',
[
'blogpost' => $blogpost,
'subview' => $subview,
]);
}
public function BlogviewAdventOfCodeList(array $blogpost)
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ 'blogpost' => $blogpost ];
include (__DIR__ . '/../fragments/blogview_aoc_list.php');
return $this->evalFragment('BlogviewAdventOfCodeList', 'blogview_aoc_list.php',
[
'blogpost' => $blogpost,
]);
}
public function BlogviewAdventOfCodeSingle(array $blogpost, string $subview)
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ 'blogpost' => $blogpost, 'subview' => $subview ];
include (__DIR__ . '/../fragments/blogview_aoc_single.php');
return $this->evalFragment('BlogviewAdventOfCodeSingle', 'blogview_aoc_single.php',
[
'blogpost' => $blogpost,
'subview' => $subview,
]);
}
public function WidgetBefunge93(string $code, string $url, bool $interactive, int $speed, bool $editable)
{
return $this->evalFragment('WidgetBefunge93', 'widget_befunge93.php',
[
'code' => $code,
'url' => $url,
'interactive' => $interactive,
'speed' => $speed,
'editable' => $editable,
]);
}
public function WidgetBFJoust(string $codeLeft, string $codeRight)
{
return $this->evalFragment('WidgetBFJoust', 'widget_bfjoust.php',
[
'code_left' => $codeLeft,
'code_right' => $codeRight,
]);
}
}

View File

@ -33,9 +33,9 @@ class Euler
$a['url_raw'] = 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-' . $n3p . '.b93';
$a['url_github'] = 'https://github.com/Mikescher/Project-Euler_Befunge';
$a['file_description'] = (__DIR__ . '/../statics/euler/Euler_Problem-'.$n3p.'_description.md');
$a['file_code'] = (__DIR__ . '/../statics/euler/Euler_Problem-'.$n3p.'.b93');
$a['file_explanation'] = (__DIR__ . '/../statics/euler/Euler_Problem-'.$n3p.'_explanation.md');
$a['file_description'] = (__DIR__ . '/../../statics/euler/Euler_Problem-'.$n3p.'_description.md');
$a['file_code'] = (__DIR__ . '/../../statics/euler/Euler_Problem-'.$n3p.'.b93');
$a['file_explanation'] = (__DIR__ . '/../../statics/euler/Euler_Problem-'.$n3p.'_explanation.md');
return $a;
}

View File

@ -67,29 +67,14 @@ class ParsedownCustom extends ParsedownExtra
protected function handleBFJoust(array $Element)
{
global $PARAM_CODE_LEFT;
global $PARAM_CODE_RIGHT;
$split = preg_split("/-{16,}/", $Element['text']);
$PARAM_CODE_LEFT = trim($split[0]);
$PARAM_CODE_RIGHT = trim($split[1]);
return require (__DIR__ . '/../fragments/widget_bfjoust.php');
return Website::inst()->fragments->WidgetBFJoust(trim($split[0]), trim($split[1]));
}
protected function handleBef93(array $Element)
{
global $PARAM_BEFUNGE93RUNNER;
$PARAM_BEFUNGE93RUNNER =
[
'code' => $Element['text'],
'url' => '',
'interactive' => $Element['b93_interactive'],
'speed' => $Element['b93_speed'],
'editable' => $Element['b93_editable'],
];
return require (__DIR__ . '/../fragments/widget_befunge93.php');
return Website::inst()->fragments->WidgetBefunge93($Element['text'], '', $Element['b93_interactive'], $Element['b93_speed'], $Element['b93_editable']);
}
protected function blockTable($Line, array $Block = null)

View File

@ -33,21 +33,21 @@ else
if ($post['type'] === 'plain')
{
$SITE->fragments->BlogviewPlain($post);
echo $SITE->fragments->BlogviewPlain($post);
}
elseif ($post['type'] === 'markdown')
{
$SITE->fragments->BlogviewMarkdown($post);
echo $SITE->fragments->BlogviewMarkdown($post);
}
elseif ($post['type'] === 'euler')
{
if ($subview === '') $SITE->fragments->BlogviewEulerList($post);
else $SITE->fragments->BlogviewEulerSingle($post, $subview);
if ($subview === '') echo $SITE->fragments->BlogviewEulerList($post);
else echo $SITE->fragments->BlogviewEulerSingle($post, $subview);
}
elseif ($post['type'] === 'aoc')
{
if ($subview === '') $SITE->fragments->BlogviewAdventOfCodeList($post);
else $SITE->fragments->BlogviewAdventOfCodeSingle($post, $subview);
if ($subview === '') echo $SITE->fragments->BlogviewAdventOfCodeList($post);
else echo $SITE->fragments->BlogviewAdventOfCodeSingle($post, $subview);
}
?>

View File

@ -12,12 +12,12 @@ $FRAME_OPTIONS->canonical_url = 'https://www.mikescher.com';
$FRAME_OPTIONS->activeHeader = 'home';
?>
<?php $SITE->fragments->PanelEuler(); ?>
<?php echo $SITE->fragments->PanelEuler(); ?>
<?php $SITE->fragments->PanelPrograms(); ?>
<?php echo $SITE->fragments->PanelPrograms(); ?>
<?php $SITE->fragments->PanelBlog(); ?>
<?php echo $SITE->fragments->PanelBlog(); ?>
<?php $SITE->fragments->PanelBooks(); ?>
<?php echo $SITE->fragments->PanelBooks(); ?>
<?php $SITE->fragments->PanelAdventOfCode(); ?>
<?php echo $SITE->fragments->PanelAdventOfCode(); ?>