euler - bestof
This commit is contained in:
parent
512e357e77
commit
91613683c2
@ -52,6 +52,23 @@ $problems = Euler::listAll();
|
|||||||
I recommend using <a href="/programs/view/BefunUtils">BefunExec</a>. I specially made that interpreter for this project. It can run befunge code with around 6.5 MHz <i>(on my machine)</i>
|
I recommend using <a href="/programs/view/BefunUtils">BefunExec</a>. I specially made that interpreter for this project. It can run befunge code with around 6.5 MHz <i>(on my machine)</i>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<h1>My favorites:</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-101">Problem 101 - Optimum polynomial</a></li>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-098">Problem 098 - Anagramic squares</a></li>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-091">Problem 091 - Right triangles with integer coordinates</a></li>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-079">Problem 079 - Passcode derivation</a></li>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-059">Problem 059 - XOR decryption</a></li>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-053">Problem 053 - Combinatoric selections</a></li>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-043">Problem 043 - Sub-string divisibility</a></li>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-017">Problem 017 - Number letter counts</a></li>
|
||||||
|
<li><a href="/blog/1/Project_Euler_with_Befunge/problem-015">Problem 015 - Lattice paths</a></li>
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h1>All solved problems</h1>
|
||||||
<div class="mdtable_container">
|
<div class="mdtable_container">
|
||||||
<table id="PEB_tableProblems" class="mdtable">
|
<table id="PEB_tableProblems" class="mdtable">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -53,7 +53,7 @@ $max = ceil($max / 20) * 20;
|
|||||||
'code' => file_get_contents($problem['file_code']),
|
'code' => file_get_contents($problem['file_code']),
|
||||||
'url' => $problem['url_raw'],
|
'url' => $problem['url_raw'],
|
||||||
'interactive' => !$problem['abbreviated'],
|
'interactive' => !$problem['abbreviated'],
|
||||||
'speed' => $problem['steps'] < 500000 ? 2 : 3,
|
'speed' => $problem['steps'] < 15000 ? 1 : ($problem['steps'] < 500000 ? 2 : 3),
|
||||||
'editable' => false,
|
'editable' => false,
|
||||||
];
|
];
|
||||||
echo require (__DIR__ . '/../fragments/widget_befunge93.php');
|
echo require (__DIR__ . '/../fragments/widget_befunge93.php');
|
||||||
|
@ -185,7 +185,6 @@ try {
|
|||||||
//TODO better gh widget
|
//TODO better gh widget
|
||||||
//TODO remove db table prefixes
|
//TODO remove db table prefixes
|
||||||
//TODO euler insert+show 32bit | 64bit mode
|
//TODO euler insert+show 32bit | 64bit mode
|
||||||
//TODO euler best of on top of list (?)
|
|
||||||
//TODO optimize image sizes for display/download (? - auto?)
|
//TODO optimize image sizes for display/download (? - auto?)
|
||||||
//TODO send cache header (?)
|
//TODO send cache header (?)
|
||||||
//TODO global uncached error logger -> send by mail
|
//TODO global uncached error logger -> send by mail
|
||||||
|
@ -12,31 +12,29 @@ $post = Blog::getBlogpost($id);
|
|||||||
|
|
||||||
if ($post === NULL) httpError(404, 'Blogpost not found');
|
if ($post === NULL) httpError(404, 'Blogpost not found');
|
||||||
|
|
||||||
|
$isSubEuler = ($post['type'] === 'euler' && $subview !== '');
|
||||||
|
$eulerproblem = null;
|
||||||
|
if ($isSubEuler)
|
||||||
|
{
|
||||||
|
require_once(__DIR__ . '/../internals/euler.php');
|
||||||
|
$eulerproblem = Euler::getEulerProblemFromStrIdent($subview);
|
||||||
|
}
|
||||||
|
if ($eulerproblem === null) $isSubEuler = false;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Mikescher.com - Blog</title>
|
<title>Mikescher.com - <?php echo ($isSubEuler ? $eulerproblem['title'] : $post['title']); ?></title>
|
||||||
<meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/>
|
<meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/>
|
||||||
<link rel="icon" type="image/png" href="/data/images/favicon.png"/>
|
<link rel="icon" type="image/png" href="/data/images/favicon.png"/>
|
||||||
<?php printCSS(); ?>
|
<?php printCSS(); ?>
|
||||||
<?php
|
<?php echo '<link rel="canonical" href="' . ($isSubEuler ? $eulerproblem['canonical'] : $post['canonical']) . '"/>'; ?>
|
||||||
if ($post['type'] === 'euler' && $subview !== '')
|
|
||||||
{
|
|
||||||
require_once(__DIR__ . '/../internals/euler.php');
|
|
||||||
$problem = Euler::getEulerProblemFromStrIdent($subview);
|
|
||||||
if ($problem !== NULL) echo '<link rel="canonical" href="' . $problem['canonical'] . '"/>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
echo '<link rel="canonical" href="' . $post['canonical'] . '"/>';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="mastercontainer">
|
<div id="mastercontainer">
|
||||||
|
|
||||||
<?php $HEADER_ACTIVE = ($post['type']==='euler' && $subview==='') ? 'euler' : 'none'; include (__DIR__ . '/../fragments/header.php'); ?>
|
<?php $HEADER_ACTIVE = ($isSubEuler ? 'euler' : 'none'); include (__DIR__ . '/../fragments/header.php'); ?>
|
||||||
|
|
||||||
<div id="content" class="content-responsive">
|
<div id="content" class="content-responsive">
|
||||||
|
|
||||||
|
@ -8,3 +8,117 @@ The code here was a tight fit into the Befunge-93 80x25 grid, not because of som
|
|||||||
Here we generate all combinations from the last digit to the first, we significantly limit the amount of possible combinations by checking the constraints for every number.
|
Here we generate all combinations from the last digit to the first, we significantly limit the amount of possible combinations by checking the constraints for every number.
|
||||||
For example we are at `???????410`, we then don't need to evaluate the first 7 digits because constraint 7 is violated (divisibility of d_789 by 17).
|
For example we are at `???????410`, we then don't need to evaluate the first 7 digits because constraint 7 is violated (divisibility of d_789 by 17).
|
||||||
This way instead of evaluating `3,628,800` possibilities we only have to look at `1702`.
|
This way instead of evaluating `3,628,800` possibilities we only have to look at `1702`.
|
||||||
|
|
||||||
|
Pen-and-paper solution
|
||||||
|
======================
|
||||||
|
|
||||||
|
|
||||||
|
We can rule out a lot of combinations by simply looking at our rules. I divided my thought processes into steps:
|
||||||
|
|
||||||
|
**Step 1:**
|
||||||
|
|
||||||
|
- d_1 != d_2 != d_3 != d_4 != d_5 != d_6 != d_7 != d_8 != d_9 *(palindromic)*
|
||||||
|
- d_1 is not `0`
|
||||||
|
- d_234 is divisible by 2 => d_4 is even
|
||||||
|
- d_345 is divisible by 3 => `(d_3 + d_4 + d_5) % 3 = 0`
|
||||||
|
- d_456 is divisible by 5 => d_6 is `0` or `5`
|
||||||
|
- d_567 is divisible by 7
|
||||||
|
- d_678 is divisible by 11
|
||||||
|
- d_789 is divisible by 13
|
||||||
|
- d_89A is divisible by 17
|
||||||
|
|
||||||
|
**Step 2:**
|
||||||
|
|
||||||
|
if d_6 is `0` then d_678 starts with a `0`, and because d_678 is divisible by 11: `d_7 == d_8`. This conflicts with our palindrome rule.
|
||||||
|
|
||||||
|
Therefore d_6 = `5`.
|
||||||
|
|
||||||
|
**Step 3:**
|
||||||
|
|
||||||
|
d_6 is `5` and d_678 is divisible by 11. There are only 8 possibilities for d_678:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
506, 517, 528, 539, 561, 572, 583, 594
|
||||||
|
~~~
|
||||||
|
|
||||||
|
**Step 4:**
|
||||||
|
|
||||||
|
d_789 is divisible by 13, together with the possibilities for d_78 there are only 4 possibilities left for d_6789:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
5286, 5390, 5728, 5832
|
||||||
|
~~~
|
||||||
|
|
||||||
|
**Step 5:**
|
||||||
|
|
||||||
|
d_89A is divisible by 17, then we can again - together with the previous result - look at the possibilities for d_6789A:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
52867, 53901, 57289
|
||||||
|
~~~
|
||||||
|
|
||||||
|
**Step 6:**
|
||||||
|
|
||||||
|
d_567 is divisible by 7, d_6 is `5` and d_7 is `2`, `3` or `7`. There are now only 2 possible values for d_56789A left:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
357289, 952867
|
||||||
|
~~~
|
||||||
|
|
||||||
|
**Step 7:**
|
||||||
|
|
||||||
|
Both values contain `2`, `5`, `7`, `8`, `9`, so d_1 - d_4 can't be any of those
|
||||||
|
|
||||||
|
**Step 8:**
|
||||||
|
|
||||||
|
d_345 is divisible by 3. d_5 is `3 or 9` and d_4 is even and the possible digits are `0`, `1`, `2`, `3`, `4`, `6` and `9` (`9` only for d_5).
|
||||||
|
The possible values for d_345 are therefore:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
063, 069, 309, 603, 609
|
||||||
|
~~~
|
||||||
|
|
||||||
|
And so the possible values for d_3456789A:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
06357289, 06952867, 30952867, 60357289, 60952867
|
||||||
|
~~~
|
||||||
|
|
||||||
|
number 2 and 5 are not palindromic, so the numbers left are:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
06357289, 30952867, 60357289
|
||||||
|
~~~
|
||||||
|
|
||||||
|
**Step 9:**
|
||||||
|
|
||||||
|
The only numbers left are now `1` and `4` and there are no rules left to consider.
|
||||||
|
We can now list the resulting numbers by using the 3 numbers from before and every combination of `1` and `4`:
|
||||||
|
|
||||||
|
- 14 06357289
|
||||||
|
- 41 06357289
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
- 14 30952867
|
||||||
|
- 41 30952867
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
- 14 60357289
|
||||||
|
- 41 60357289
|
||||||
|
|
||||||
|
**Step 10:**
|
||||||
|
|
||||||
|
The final step is now to calculate the sum of these numbers:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
1406357289
|
||||||
|
+ 4106357289
|
||||||
|
+ 1430952867
|
||||||
|
+ 4130952867
|
||||||
|
+ 1460357289
|
||||||
|
+ 4160357289
|
||||||
|
|
||||||
|
= 16695334890
|
||||||
|
~~~
|
Loading…
Reference in New Issue
Block a user