Skip to content

Commit

Permalink
Merge pull request #82 from project-lovelace/ali/new-batch
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ramadhan authored Mar 25, 2021
2 parents 838c050 + 1c47181 commit eab576f
Show file tree
Hide file tree
Showing 19 changed files with 512 additions and 4 deletions.
2 changes: 1 addition & 1 deletion populate_production_env.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ echo "Migrating Django changes..."
docker-compose -f docker-compose.prod.yml exec django python manage.py migrate --no-input

echo "Populating Django database..."
docker-compose -f docker-compose.prod.yml exec django python manage.py loaddata lovelace_website.json
docker-compose -f docker-compose.prod.yml exec django python manage.py loaddata lovelace_django_dumpdata.json

echo "Collecting static files..."
docker-compose -f docker-compose.prod.yml exec django python manage.py collectstatic
Expand Down
2 changes: 1 addition & 1 deletion populate_staging_env.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ echo "Migrating Django changes..."
docker-compose -f docker-compose.staging.yml exec django python manage.py migrate --no-input

echo "Populating Django database..."
docker-compose -f docker-compose.staging.yml exec django python manage.py loaddata lovelace_website.json
docker-compose -f docker-compose.staging.yml exec django python manage.py loaddata lovelace_django_dumpdata.json

echo "Collecting static files..."
docker-compose -f docker-compose.staging.yml exec django python manage.py collectstatic
Expand Down
6 changes: 6 additions & 0 deletions spin_up_lovelace_website.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd src/
docker-compose build
docker-compose up --detach

5 changes: 4 additions & 1 deletion src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ echo "Migrating Django changes..."
python manage.py migrate --no-input

echo "Populating Django database..."
python manage.py loaddata lovelace_website.json
python manage.py loaddata lovelace_django_dumpdata.json

echo "Collecting static files..."
python manage.py collectstatic

exec "$@"
82 changes: 82 additions & 0 deletions src/problems/templates/problems/compound-interest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{% extends "problems/problem.html" %}

{% load static %}

{% block you_will_learn %}
the most powerful force in the world according to Einstein. <sup>[<a href="https://quoteinvestigator.com/2019/09/09/interest/">citation needed</a>]</sup>
{% endblock %}

{% block problem_body %}
<p class="has-text-justified">
Compound interest is when interest on a loan or investment is added back to the loan or investment. So it's like
interest on interest! Compounding leads to exponential growth so it makes your investments grow big over time but
also makes it much harder to pay off predatory loans and credit card debt.
</p>
<br>
<p class="has-text-justified">
If you start with an amount of money $m$ and the compound interest is calculated once a year with interest rate $r$
(as a fraction between 0 and 1) then after $n$ years you end up with a new amount $M$ given by

$$ M = m (1 + r)^n $$
</p>
<br>

This plot shows the growth of $m = 1,000$ dollars compounded every year at 10% ($r = 0.1$) for $n = 25$ years.

<figure style="text-align: center;">
<div id="compound-interest-figure"></id>
</figure>
<br>

<p class="has-text-justified">
Submit some code with a function <tt>compound_interest(m, r, n)</tt> that computes the final amount $M$ after
starting with an amount $m$ compounded yearly at a rate $r$ for $n$ years.
</p>
{% endblock %}

{% block input_description %}
Starting amount $m$, rate $r$, and number of years $n$.
{% endblock %}

{% block output_description %}
Final amount $M$.
{% endblock %}

{% block examples %}
<article class="message">
<div class="message-header">
<p>Example</p>
</div>
<div class="message-body"
style="font-family: monospace; text-align: justify; word-wrap: break-word; white-space:pre;"><b>Input</b>: 1000, 0.07, 25
<b>Output</b>: 5427.43</div>
</article>
{% endblock %}

{% block function_signature %}
compound_interest(m, r, n)
{% endblock %}

{% block notes_and_references %}
<div class="content">
<h3>Notes</h3>
<ul>
<li>
Charging compound interest on loans was and is still considered a kind of <a href="https://en.wikipedia.org/wiki/Usury">usury</a>
by many religions and societies. The Romans and the Christian Bible condemn charging interest on loans to poor people as
it is seen as a form of exploitation. On the extreme end, Islam forbids the charging of any kind of interest as it sees borrowing
and lending as social transactions aimed at benefiting others and thus should not be profitable.
</li>
<li>
The number $e$ was actually discovered by Jacob Bernoulli in 1683 when investigating compound interest.
Now of course called Euler's number because of <a href="https://en.wikipedia.org/wiki/Stigler%27s_law_of_eponymy">Stigler's law</a>.
</li>
<li>
The <a href="https://en.wikipedia.org/wiki/Rule_of_72">Rule of 72</a> is a quick rule/approximation for figuring
out how long it would take for the amount to double: it's $72/r$ where $r$ is the interest rate as a percentage.
</li>
</ul>
</div>
{% endblock %}

{% block discourse_topic_id %}x{% endblock %}
49 changes: 49 additions & 0 deletions src/problems/templates/problems/logistic-growth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends "problems/problem.html" %}

{% load static %}

{% block you_will_learn %}
modeling population growth and numerically solving a differential equation.
{% endblock %}

{% block problem_body %}
<p class="has-text-justified">
$$ \frac{dP}{dt} = rP \left( 1 - \frac{P}{K} \right) $$

$$ P^{n+1} = P^n + \Delta t rP^n \left( 1 - \frac{P^n}{K} \right) $$
</p>
<br>

<figure style="text-align: center;">
<div id="logistic-growth-app"></id>
</figure>
<br>
{% endblock %}

{% block input_description %}
P^0, \Delta t, r, K, N
{% endblock %}

{% block output_description %}
P(t) = {P^0, P^1, ..., P^N}
{% endblock %}

{% block examples %}
<article class="message">
<div class="message-header">
<p>Example</p>
</div>
<div class="message-body"
style="font-family: monospace; text-align: justify; word-wrap: break-word; white-space:pre;"><b>Input</b>: $1,000, 0.07, 25
<b>Output</b>: $5,427.43</div>
</article>
{% endblock %}

{% block function_signature %}
logistic_growth(P0, dt, r, K, N)
{% endblock %}

{% block notes_and_references %}
{% endblock %}

{% block discourse_topic_id %}x{% endblock %}
106 changes: 106 additions & 0 deletions src/problems/templates/problems/plump-moose.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{% extends "problems/problem.html" %}

{% load static %}

{% block you_will_learn %}
cold moose have more fat
{% endblock %}

{% block problem_body %}
<p class="has-text-justified">
Bergmann's rule says that animals living in colder climates tend to be larger in size. Swedish scientists measured
the body mass of different moose populations in Sweden and found that the further north you go, the bigger the moose
get! Taking their data we can fit a line through it to predict the body mass of a moose at some latitude using the
equation

$$ \text{mass} = a \times \text{latitude} + b $$

where $a = 2.757$ and $b = 16.793$.
</p>
<br>

<figure style="text-align: center;">
<div id="moose-mass-figure"></id>
</figure>
<br>

<p class="has-text-justified">
Submit some code with a function <tt>moose_body_mass(latitude)</tt> that returns the expected body mass of a moose
living at the input latitude using the equation from above.
</p>
{% endblock %}

{% block input_description %}
Latitude
{% endblock %}

{% block output_description %}
The expected body mass of a moose living at the input latitude.
{% endblock %}

{% block examples %}
<article class="message">
<div class="message-header">
<p>Example</p>
</div>
<div class="message-body"
style="font-family: monospace; text-align: justify; word-wrap: break-word; white-space:pre;"><b>Input latitude</b>: 60.5
<b>Output body mass</b>: 183.5915</div>
</article>
{% endblock %}

{% block function_signature %}
moose_body_mass(latitude)
{% endblock %}

{% block notes_and_references %}
<div class="content">
<h3>Notes</h3>
<ul>
<li>
Bergmann's rule is a generalization and so it doesn't apply to every species. In fact many counter-examples to
Bergmann's rule exist but it seems to hold true in many cases (Meiri and Dayan, 2003).
</li>
<li>
The original explanation given by Bergmann (1847) for why animals are larger in colder climates is due to the need to
conserve heat. Since larger animals have a lower surface area to volume ratio, they lose less body heat per
unit mass helping to keep them warmer when it's cold. More recent studies don't support this hypothesis though
(Ashton et al., 2000).
</li>
</ul>

<h3>References</h3>
<dl>
<dt>
Sand, Cederlund &amp; Danell (1995), <a href="https://doi.org/10.1007/BF00341355">
Geographical and latitudinal variation in growth patterns and adult body size of Swedish moose (Alces alces)</a>,
Oecologia <b>102</b>, 433–442.
</dt>
<dd>This is where we got the data from.</dd>
<br>

<dt>
Bergmann (1847), <a href="https://books.google.com/books?id=EHo-AAAAcAAJ&amp;pg=PA3">
Über die Verhältnisse der Wärmeökonomie der Thiere zu ihrer Grösse</a>, Göttinger Studien <b>3</b>(1), 595–708.
</dt>
<dd>
This is the original article by Bergmann in German at over a 100 pages long! Google translates the title to English
as "About the relation of the heat economy of animals to their size".
</dd>
<br>

<dt>
Meiri and Dayan (2003), <a href="https://doi.org/10.1046/j.1365-2699.2003.00837.x">On the validity of Bergmann's rule</a>,
Journal of Biogeography <b>30</b>, 331-351.
</dt>
<br>

<dt>
Ashton, Tracy, &amp; de Queiroz (2000), <a href="https://doi.org/10.1086/303400 ">
Is Bergmann’s Rule Valid for Mammals?</a>, The American Naturalist <b>156</b>(4), 390-415.
</dl>
<br>
</div>
{% endblock %}

{% block discourse_topic_id %}x{% endblock %}
54 changes: 54 additions & 0 deletions src/problems/templates/problems/rna-translation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{% extends "problems/problem.html" %}

{% load static %}

{% block you_will_learn %}
genetics and strings.
{% endblock %}

{% block problem_body %}
<p class="has-text-justified">
As you learned in <a href"dna-transcription.html">DNA transcription</a>, the first step in converting DNA to proteins
is transcribing the DNA into RNA. The second step is translating the RNA into a chain of amino acids, called a
polypeptide. The process is biochemically complex but the resulting amino acid sequence is quite simple: each set of
three base pairs (called a nucleotide triplet or codon) is translated to a single amino acid. The chart below shows
how to translate each codon to an amino acid.
</p>
<br>

<figure style="text-align: center;">
<img style="width: 75%; margin: 0 auto;" src="{% static 'img/codon_table.png' %}">
<figcaption class="help">
</figcaption>
</figure>
{% endblock %}

All sequences begin with the start codon and end with one of the end codons.

{% block input_description %}
An RNA sequence.
{% endblock %}

{% block output_description %}
A sequence of amino acids.
{% endblock %}

{% block examples %}
<article class="message">
<div class="message-header">
<p>Example</p>
</div>
<div class="message-body"
style="font-family: monospace; text-align: justify; word-wrap: break-word; white-space:pre;"><b>Input</b>: $1,000, 0.07, 25
<b>Output</b>: $5,427.43</div>
</article>
{% endblock %}

{% block function_signature %}
translate(rna)
{% endblock %}

{% block notes_and_references %}
{% endblock %}

{% block discourse_topic_id %}x{% endblock %}
2 changes: 1 addition & 1 deletion src/problems/templates/problems/speed-of-light.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load static %}

{% block you_will_learn %}
submitting code and that light is <i>fast</i>.
light is <i>fast</i>.
{% endblock %}

{% block problem_body %}
Expand Down
7 changes: 7 additions & 0 deletions src/static/code_stubs/c/compound_interest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
double compound_interest(double amount, double rate, int years) {
double new_amount = 0.0;

// Your code goes here!

return new_amount;
}
7 changes: 7 additions & 0 deletions src/static/code_stubs/c/plump_moose.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
double moose_body_mass(double latitude) {
double mass = 0.0;

// Your code goes here!

return mass;
}
7 changes: 7 additions & 0 deletions src/static/code_stubs/javascript/compound_interest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function compound_interest(amount, rate, years) {
var new_amount = 0

// Your code goes here!

return new_amount
}
7 changes: 7 additions & 0 deletions src/static/code_stubs/javascript/plump_moose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function moose_body_mass(latitude) {
var mass = 0

// Your code goes here!

return mass
}
7 changes: 7 additions & 0 deletions src/static/code_stubs/julia/compound_interest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function compound_interest(amount, rate, years)
new_amount = 0

# Your code goes here!

return new_mount
end
7 changes: 7 additions & 0 deletions src/static/code_stubs/julia/plump_moose.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function moose_body_mass(latitude)
mass = 0

# Your code goes here!

return mass
end
6 changes: 6 additions & 0 deletions src/static/code_stubs/python/compound_interest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def compound_interest(amount, rate, years):
new_amount = 0

# Your code goes here!

return new_amount
Loading

0 comments on commit eab576f

Please sign in to comment.