     ]
    },
    {
     "cell_type": "code",
     "execution_count": 5,
     "metadata": {
      "collapsed": false
     },
     "outputs": [
      {
 
</s> remove    "execution_count": 4,
 </s> add    "execution_count": 2, </s> remove     "collapsed": false
   },
   "outputs": [],
   "source": [
    "def fib_recursive(n):\n",
    "    if n == 0 or n == 1:\n",
    "        return n\n",
    "    else:\n",
    "        return fib_recursive(n-1) + fib_recursive(n-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
 </s> add     "collapsed": true </s> remove     "def fib_dynamic(n):\n",
    "    # TODO: Implement me\n",
    "    pass"
 </s> add     "class Math(object):\n",
    "\n",
    "    def fib_iterative(self, n):\n",
    "        # TODO: Implement me\n",
    "        pass\n",
    "\n",
    "    def fib_recursive(self, n):\n",
    "        # TODO: Implement me\n",
    "        pass\n",
    "\n",
    "    def fib_dynamic(self, n):\n",
    "        # TODO: Implement me\n",
    "        pass" </s> remove     "def fib_iterative(n):\n",
    "    a = 0\n",
    "    b = 1\n",
    "    for _ in range(n):\n",
    "        a, b = b, a + b\n",
    "    return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def fib_dynamic(n):\n",
    "    cache = {}\n",
    "    return _fib_dynamic(n, cache)\n",
    "\n",
    "\n",
    "def _fib_dynamic(n, cache):\n",
    "    if n == 0 or n == 1:\n",
    "        return n\n",
    "    if n in cache:\n",
    "        return cache[n]\n",
    "    cache[n] = _fib_dynamic(n-1, cache) + _fib_dynamic(n-2, cache)\n",
    "    return cache[n]"
 </s> add     "class Math(object):\n",
    "\n",
    "    def fib_iterative(self, n):\n",
    "        a = 0\n",
    "        b = 1\n",
    "        for _ in range(n):\n",
    "            a, b = b, a + b\n",
    "        return a\n",
    "\n",
    "    def fib_recursive(self, n):\n",
    "        if n == 0 or n == 1:\n",
    "            return n\n",
    "        else:\n",
    "            return self.fib_recursive(n-1) + self.fib_recursive(n-2)\n",
    "\n",
    "    def fib_dynamic(self, n):\n",
    "        cache = {}\n",
    "        return self._fib_dynamic(n, cache)\n",
    "\n",
    "    def _fib_dynamic(self, n, cache):\n",
    "        if n == 0 or n == 1:\n",
    "            return n\n",
    "        if n in cache:\n",
    "            return cache[n]\n",
    "        cache[n] = self._fib_dynamic(n-1, cache) + self._fib_dynamic(n-2, cache)\n",
    "        return cache[n]" </s> remove     "    test.test_fib(fib_recursive)\n",
    "    test.test_fib(fib_dynamic)\n",
    "    test.test_fib(fib_iterative)\n",
 </s> add     "    math = Math()\n",
    "    test.test_fib(math.fib_recursive)\n",
    "    test.test_fib(math.fib_dynamic)\n",
    "    test.test_fib(math.fib_iterative)\n",
   "execution_count": 3,
     ]
    },
    {
     "cell_type": "code",
   "execution_count": 3,
     "metadata": {
      "collapsed": false
     },
     "outputs": [
      {
keep keep keep keep replace keep keep keep keep keep
 Move Fibonacci challenge code to a class (#140) 
recursion_dynamic/fibonacci/fibonacci_solution.ipynb