1
0
www.mikescher.com/www/fragments/blogview_euler_single.php

132 lines
4.4 KiB
PHP
Raw Permalink Normal View History

2018-01-01 21:07:48 +01:00
<?php
2020-01-17 00:25:29 +01:00
require_once (__DIR__ . '/../internals/website.php');
2018-01-01 21:07:48 +01:00
2020-01-17 00:25:29 +01:00
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
2018-01-01 21:07:48 +01:00
2020-01-17 00:25:29 +01:00
global $FRAGMENT_PARAM;
/** @var array $parameter */
$parameter = $FRAGMENT_PARAM;
?>
2018-01-01 21:07:48 +01:00
2020-01-17 00:25:29 +01:00
<?php
$post = $parameter['blogpost'];
$subview = $parameter['subview'];
2018-01-01 21:07:48 +01:00
2020-01-17 00:25:29 +01:00
$euler = $SITE->modules->Euler()->listAll();
$problem = $SITE->modules->Euler()->getEulerProblemFromStrIdent($subview);
2018-01-01 21:07:48 +01:00
2020-01-17 00:25:29 +01:00
if ($problem === NULL) { $FRAME_OPTIONS->forceResult(404, 'Project Euler entry not found'); return; }
2018-01-01 21:07:48 +01:00
$arr = [];
$max = 0;
foreach ($euler as $elem)
{
$max = max($max, $elem['number']);
$arr[$elem['number']] = $elem;
}
$max = ceil($max / 20) * 20;
?>
2018-01-21 15:29:01 +01:00
<div class="boxedcontent blogcontent_euler base_markdown">
2018-01-01 21:07:48 +01:00
<div style="position: relative;">
<a href="https://github.com/Mikescher/Project-Euler_Befunge" style="position: absolute; top: 0; right: 0; border: 0;">
2018-01-01 23:03:05 +01:00
<img src="/data/images/blog/github_band.png" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
2018-01-01 21:07:48 +01:00
</a>
</div>
<div class="bc_header">
<?php echo $problem['date']; ?>
</div>
<div class="bc_data">
<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>
2020-01-17 00:25:29 +01:00
<div class="bce_description"><?php echo $SITE->renderMarkdown(file_get_contents($problem['file_description'])); ?></div>
2018-01-01 21:07:48 +01:00
<br/>
2018-01-01 23:03:05 +01:00
<b>Solution:</b>
<?php
2020-01-17 00:25:29 +01:00
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);
2018-01-03 00:08:42 +01:00
if ($problem['abbreviated']) echo '<i>This program is too big to display/execute here, click [download] to get the full program. </i><br/>';
2018-01-01 23:03:05 +01:00
?>
<br/>
2018-01-01 21:07:48 +01:00
<b>Explanation:</b>
2020-01-17 00:25:29 +01:00
<div class="bce_explanation"><?php echo $SITE->renderMarkdown(file_get_contents($problem['file_explanation'])); ?></div>
2018-01-01 21:07:48 +01:00
<br/>
2018-01-01 23:03:05 +01:00
<table class="notable">
2018-01-01 21:07:48 +01:00
<tr>
<td><b>Interpreter steps:</b></td>
<td><?php echo number_format($problem['steps'], 0, null, ' '); ?></td>
</tr>
<tr>
2018-02-03 18:45:51 +01:00
<td><b>Execution time</b> (<a href="/programs/view/BefunUtils">BefunExec</a>):</td>
2018-01-03 00:55:15 +01:00
<td><?php echo formatMilliseconds($problem['time']) . ' <i>(' . (($problem['time']===0) ? '?' : number_format(($problem['steps']/$problem['time'])/1000, 2, '.', '')) . ' MHz)</i>'; ?></td>
2018-01-01 21:07:48 +01:00
</tr>
<tr>
<td><b>Program size:</b></td>
<td><?php echo $problem['width'] . ' x ' . $problem['height']; if ($problem['is93']) echo '<i> (fully conform befunge-93)</i>'; ?></td>
</tr>
<tr>
<td><b>Solution:</b></td>
<td><?php echo $problem['value']; ?></td>
</tr>
<tr>
<td><b>Solved at:</b></td>
<td><?php echo $problem['date']; ?></td>
</tr>
</table>
<br />
<br />
2019-11-08 16:09:42 +01:00
<div class="pagination">
2018-01-01 21:07:48 +01:00
<?php
$break = false;
for($i1=0;;$i1++)
{
2019-11-08 16:09:42 +01:00
echo "<div class='pag20'>\n";
2018-01-01 21:07:48 +01:00
for($i2=0;$i2<2;$i2++)
{
2019-11-08 16:09:42 +01:00
echo "<div class='pag10'>\n";
2018-01-01 21:07:48 +01:00
for($i3=0;$i3<2;$i3++)
{
2019-11-08 16:09:42 +01:00
echo "<div class='pag05'>\n";
2018-01-01 21:07:48 +01:00
for($i4=0;$i4<5;$i4++)
{
$ii = $i1*20 + $i2*10 + $i3*5 + $i4 + 1;
if ($ii > $max) {$break = true; break;}
$pii = str_pad($ii, 3, '0', STR_PAD_LEFT);
if ($ii == $problem['number'])
2019-11-08 16:09:42 +01:00
echo "<div class='pagbtn pagbtn_active'>" . $pii . "</div>\n";
2018-01-01 21:07:48 +01:00
else if (key_exists($ii, $arr))
2019-11-08 16:09:42 +01:00
echo "<a class='pagbtn' href='/blog/1/Project_Euler_with_Befunge/problem-" . $pii . "'>" . $pii . "</a>\n";
2018-01-01 21:07:48 +01:00
else
2019-11-08 16:09:42 +01:00
echo "<div class='pagbtn pagbtn_disabled'>" . $pii . "</div>\n";
2018-01-01 21:07:48 +01:00
}
2018-01-02 17:11:15 +01:00
echo "</div>\n";
2018-01-01 21:07:48 +01:00
if ($break) break;
}
2018-01-02 17:11:15 +01:00
echo "</div>\n";
2018-01-01 21:07:48 +01:00
if ($break) break;
}
2018-01-02 17:11:15 +01:00
echo "</div>\n";
2018-01-01 21:07:48 +01:00
if ($break) break;
}
?>
</div>
</div>
</div>