From 05f1dab13f31c99ed44c6c0c3eb115d95205fe17 Mon Sep 17 00:00:00 2001 From: Nils Liebreich <nilsl99@mi.fu-berlin.de> Date: Sun, 28 May 2023 21:53:28 +0200 Subject: [PATCH] Added fib5 --- exercise05_1.ipynb | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/exercise05_1.ipynb b/exercise05_1.ipynb index 3071a0f..357f424 100644 --- a/exercise05_1.ipynb +++ b/exercise05_1.ipynb @@ -77,12 +77,25 @@ "cell_type": "code", "execution_count": 6, "metadata": {}, + "outputs": [], + "source": [ + "answers = {0: 1, 1: 1}\n", + "def fib5(n):\n", + " if not n in answers:\n", + " answers[n] = fib5(n-1) + fib5(n-2)\n", + " return answers[n]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "3.06 s ± 90.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "2.55 s ± 52.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -92,14 +105,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "62.2 ns ± 1.44 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)\n" + "57.6 ns ± 0.131 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)\n" ] } ], @@ -109,14 +122,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "4.09 µs ± 193 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)\n" + "3.37 µs ± 82.7 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)\n" ] } ], @@ -126,20 +139,37 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2.76 µs ± 74.1 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)\n" + "2.2 µs ± 75.1 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)\n" ] } ], "source": [ "%timeit fib4(35)" ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "103 ns ± 0.943 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)\n" + ] + } + ], + "source": [ + "%timeit fib5(35)" + ] } ], "metadata": { @@ -158,7 +188,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.10.6" }, "orig_nbformat": 4 }, -- GitLab