Added index page and index page generator for all solutions.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
*.swp
|
*.swp
|
||||||
__pycache__
|
__pycache__
|
||||||
|
.ipynb_checkpoints
|
||||||
|
index.html
|
||||||
|
|||||||
0
html/EulerProblem001.html
Executable file → Normal file
0
html/EulerProblem001.html
Executable file → Normal file
11696
html/EulerProblem002.html
Executable file → Normal file
11696
html/EulerProblem002.html
Executable file → Normal file
File diff suppressed because one or more lines are too long
29
html/render.py
Normal file
29
html/render.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import jinja2
|
||||||
|
import os
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
|
|
||||||
|
def file_name_to_solution(name):
|
||||||
|
number = int(name.replace("EulerProblem", "").replace(".html", ""))
|
||||||
|
file_name = name
|
||||||
|
display_name = name.replace("EulerProblem", "Problem ").replace(".html", "")
|
||||||
|
return (number, file_name, display_name)
|
||||||
|
|
||||||
|
|
||||||
|
def get_solution_list(directory="./"):
|
||||||
|
l = [file_name_to_solution(f) for f in os.listdir(directory)
|
||||||
|
if f.endswith(".html") and f.startswith("EulerProblem")]
|
||||||
|
l.sort(key=itemgetter(0))
|
||||||
|
return l
|
||||||
|
|
||||||
|
|
||||||
|
def render_solutions(solutions):
|
||||||
|
loader = jinja2.FileSystemLoader(searchpath="./")
|
||||||
|
env = jinja2.Environment(loader=loader)
|
||||||
|
template = env.get_template("template.html")
|
||||||
|
d = {"solutions": solutions}
|
||||||
|
with open("index.html", 'w') as f:
|
||||||
|
f.write(template.render(**d))
|
||||||
|
|
||||||
|
|
||||||
|
render_solutions(get_solution_list())
|
||||||
53
html/template.html
Normal file
53
html/template.html
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<!-- Required meta tags -->
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
<!-- Bootstrap CSS -->
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||||
|
|
||||||
|
<title>Project Euler Solutions</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<div class="navbar navbar-dark bg-dark box-shadow">
|
||||||
|
<div class="container d-flex justify-content-between">
|
||||||
|
<a href="#" class="navbar-brand d-flex align-items-center">
|
||||||
|
<strong>My Project Euler Solutions</strong>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main role="main">
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="row" style="padding-top: 40px;">
|
||||||
|
<div class="col">
|
||||||
|
<ul>
|
||||||
|
{% for _, a, t in solutions %}
|
||||||
|
<li><a href="{{a}}">{{t}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row" style="padding-top: 40px;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Optional JavaScript -->
|
||||||
|
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||||
|
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -16,7 +16,9 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {
|
||||||
|
"collapsed": true
|
||||||
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def fibonacci_generator():\n",
|
"def fibonacci_generator():\n",
|
||||||
@@ -58,7 +60,9 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {},
|
"metadata": {
|
||||||
|
"collapsed": true
|
||||||
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def get_even_fibonaccis_smaller_or_equal_four_million():\n",
|
"def get_even_fibonaccis_smaller_or_equal_four_million():\n",
|
||||||
@@ -82,7 +86,9 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -96,6 +102,36 @@
|
|||||||
"f = get_even_fibonaccis_smaller_or_equal_four_million()\n",
|
"f = get_even_fibonaccis_smaller_or_equal_four_million()\n",
|
||||||
"print(sum(f))"
|
"print(sum(f))"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"I looked at the solutions in the forum and I kind of forgot about simple straight forward approaches. There is no need to create a list and the sum it up. Instead I can simply increment a counter which will be much faster, but less readable maybe."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"4613732\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"r, a, b = 0, 0, 1\n",
|
||||||
|
"while b <= 4000000:\n",
|
||||||
|
" if b % 2 == 0: r += b\n",
|
||||||
|
" a, b = b, a + b\n",
|
||||||
|
"print(r)"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@@ -114,7 +150,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.6.3"
|
"version": "3.5.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
Reference in New Issue
Block a user