diff --git a/recursion-dynamic/fibonacci.ipynb b/recursion-dynamic/fibonacci.ipynb index 17963e7..0fda31c 100644 --- a/recursion-dynamic/fibonacci.ipynb +++ b/recursion-dynamic/fibonacci.ipynb @@ -55,6 +55,17 @@ "## Code" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "num_items = 10" + ] + }, { "cell_type": "code", "execution_count": null, @@ -67,9 +78,9 @@ " if n == 0 or n == 1:\n", " return n\n", " else:\n", - " return fib(n-1) + fib(n-2)\n", + " return fib_recursive(n-1) + fib_recursive(n-2)\n", "\n", - "for i in xrange(0, 10):\n", + "for i in xrange(0, num_items):\n", " print(fib_recursive(i))" ] }, @@ -81,8 +92,7 @@ }, "outputs": [], "source": [ - "n = 7\n", - "cache = [None] * (n + 1)\n", + "cache = [None] * (num_items + 1)\n", "\n", "def fib_dynamic(n):\n", " if n == 0 or n == 1:\n", @@ -92,7 +102,7 @@ " cache[n] = fib_dynamic(n-1) + fib_dynamic(n-2)\n", " return cache[n]\n", "\n", - "for i in xrange(0, 10):\n", + "for i in xrange(0, num_items):\n", " print(fib_dynamic(i))" ] }, @@ -100,7 +110,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": true + "collapsed": false }, "outputs": [], "source": [ @@ -116,7 +126,7 @@ " n_minus_2, n_minus_1 = n_minus_1, total\n", " return total\n", "\n", - "for i in xrange(0, 10):\n", + "for i in xrange(0, num_items):\n", " print(fib_iterative(i))" ] }