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

136 lines
4.5 KiB
PHP
Raw Normal View History

2018-01-01 21:07:48 +01:00
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/blog.php');
require_once (__DIR__ . '/../internals/euler.php');
2018-01-01 23:03:05 +01:00
require_once (__DIR__ . '/../internals/ParsedownCustom.php');
2018-01-01 21:07:48 +01:00
$subview = $OPTIONS['subview'];
$euler = Euler::listAll();
2018-01-02 19:41:41 +01:00
$problem = Euler::getEulerProblemFromStrIdent($subview);
2018-01-01 21:07:48 +01:00
2018-01-03 17:28:08 +01:00
if ($problem === NULL) httpError(404, 'Project Euler entry not found');
2018-01-01 21:07:48 +01:00
2018-01-01 23:03:05 +01:00
$pd = new ParsedownCustom();
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>
<div class="bce_description"><?php echo $pd->text(file_get_contents($problem['file_description'])); ?></div>
<br/>
2018-01-01 23:03:05 +01:00
<b>Solution:</b>
<?php
2018-01-03 00:08:42 +01:00
global $PARAM_BEFUNGE93RUNNER;
$PARAM_BEFUNGE93RUNNER =
[
'code' => file_get_contents($problem['file_code']),
'url' => $problem['url_raw'],
'interactive' => !$problem['abbreviated'],
2018-01-26 22:27:22 +01:00
'speed' => $problem['steps'] < 15000 ? 1 : ($problem['steps'] < 500000 ? 2 : 3),
2018-01-03 00:08:42 +01:00
'editable' => false,
];
2018-01-26 21:12:04 +01:00
echo require (__DIR__ . '/../fragments/widget_befunge93.php');
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>
<div class="bce_explanation"><?php echo $pd->text(file_get_contents($problem['file_explanation'])); ?></div>
<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 />
<div class="bce_pagination">
<?php
$break = false;
for($i1=0;;$i1++)
{
2018-01-02 17:11:15 +01:00
echo "<div class='bce_pag20'>\n";
2018-01-01 21:07:48 +01:00
for($i2=0;$i2<2;$i2++)
{
2018-01-02 17:11:15 +01:00
echo "<div class='bce_pag10'>\n";
2018-01-01 21:07:48 +01:00
for($i3=0;$i3<2;$i3++)
{
2018-01-02 17:11:15 +01:00
echo "<div class='bce_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'])
2018-01-02 17:11:15 +01:00
echo "<div class='bce_pagbtn bce_pagbtn_active'>" . $pii . "</div>\n";
2018-01-01 21:07:48 +01:00
else if (key_exists($ii, $arr))
2018-01-02 17:11:15 +01:00
echo "<a class='bce_pagbtn' href='/blog/1/Project_Euler_with_Befunge/problem-" . $pii . "'>" . $pii . "</a>\n";
2018-01-01 21:07:48 +01:00
else
2018-01-02 17:11:15 +01:00
echo "<div class='bce_pagbtn bce_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>