This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · posts/compound-interest

Compound interest

$1000 at 5% a year becomes $1628.89 in ten years if the interest is added once a year, and $1647.01 if it is added monthly. Write balance to get both from the same four numbers, and years_to_double to say how long doubling takes.

Interest added times a year is each time, applied times over years. Getting that substitution right is most of the exercise, and the two numbers above are far enough apart that a test fails if you use and where and belong.

Monthly beats annual by dollars here. Weekly beats monthly by less, daily by less again, and no matter how often the interest is added the balance never passes . Once the tests pass, try a few values of to see it approach that limit.

years_to_double is the question the doubling-time post answers: is in the exponent, and taking the logarithm of both sides brings it down.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

This is a problem: its tests fail until the functions in it are written. Edit a cell and run it to try; the cells below it show whether the tests pass.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 26–55