Skip to content

Commit

Permalink
Flesh out Compound interest problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ramadhan committed Mar 25, 2021
1 parent 05cd114 commit 1c47181
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 13 deletions.
26 changes: 16 additions & 10 deletions src/problems/templates/problems/compound-interest.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load static %}

{% block you_will_learn %}
cold moose are plump.
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 %}
Expand All @@ -15,28 +15,31 @@
<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) then after $n$ years you end up with new amount $M$ given by
(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 $M$ given $m$, $r$, and $n$.
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 %}
m, r, n
Starting amount $m$, rate $r$, and number of years $n$.
{% endblock %}

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

{% block examples %}
Expand All @@ -45,8 +48,8 @@
<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>
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 %}

Expand All @@ -59,11 +62,14 @@
<h3>Notes</h3>
<ul>
<li>
Compound interest was and is considered a kind of usury by many religions and even by Roman law.
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 Stigler's law.
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
Expand Down
2 changes: 1 addition & 1 deletion src/problems/templates/problems/plump-moose.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load static %}

{% block you_will_learn %}
cold moose are plump.
cold moose have more fat
{% endblock %}

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

// Your code goes here!

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

// Your code goes here!

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

// Your code goes here!

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

# Your code goes here!

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

# Your code goes here!

return new_amount
14 changes: 12 additions & 2 deletions src/static/visualization/compound-interest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function visualize_test_case(input, output, expected, n) {
document.getElementById(`input${n}`).innerHTML =
`<b>Input</b>: m = ${input[0]}, r = ${input[1]}, n = ${input[2]} <br>`

document.getElementById(`output${n}`).innerHTML =
`<b>Output</b>: ${output[0]} (expected ${expected[0]}) <br>`

return
}

function compound_interest(amount, rate, years) {
return amount * (1 + rate) ** years
}
Expand All @@ -8,7 +18,7 @@ function make_compound_interest_figure() {
var years = 25

var year = new Array(years)
for (n = 1; n <= years; n++) {
for (n = 0; n <= years; n++) {
year[n] = n
}

Expand All @@ -31,4 +41,4 @@ function make_compound_interest_figure() {
return
}

make_compound_interest_figure()
make_compound_interest_figure()

0 comments on commit 1c47181

Please sign in to comment.