diff --git a/iml_assignment1_solved.ipynb b/iml_assignment1_solved.ipynb new file mode 100644 index 0000000..6d1b155 --- /dev/null +++ b/iml_assignment1_solved.ipynb @@ -0,0 +1,598 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + }, + "colab": { + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "whjkuflGLNWu" + }, + "source": [ + "# Fibonacci Solver\n", + "\n", + "The Fibonacci Sequence is the series of numbers:\n", + "\n", + "` 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... `\n", + "\n", + "The next number is found by adding up the two numbers before it:\n", + "\n", + "the `2` is found by adding the two numbers before it `(1+1)`,\n", + "the `3` is found by adding the two numbers before it `(1+2)`,\n", + "the `5` is `(2+3)`,\n", + "and so on!\n", + "\n", + "## Coding it up in Python\n", + "Just initialize to variables with the first two numbers of the Fibonacci sequence. Then add them up and print the result.\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "p58ac2HULNWv" + }, + "source": [ + "# Starting Point\n", + "first_number = 0\n", + "second_number = 1\n", + "result = first_number + second_number\n", + "\n", + "print(result)" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xSyPoS1bLNWy" + }, + "source": [ + "You now need to do this multiple times, so you need a ***loop***\n", + "To use a loop you need to know how many times you want to loop for. \n", + "For now, create a loop that prints **20** numbers (from 0 to 19). To do this in python you can create a ***for loop*** using the `range` function which will run the function for every number in the range.\n", + "(TIP: Python is a ***0 based*** language which means it starts counting from 0 not 1 as a human normally would.)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "tTsWxVxMLNWy" + }, + "source": [ + "for count in range(20):\n", + " print(count)" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "INNU9p8zLNW0" + }, + "source": [ + "Now use the loop to compute the first 20 elements of the Fibonacci sequence." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "4Hf59jqgLNW1" + }, + "source": [ + "# Starting Point\n", + "first_number = 0\n", + "second_number = 1\n", + "\n", + "for count in range(20):\n", + " result = first_number + second_number\n", + " print(result)\n", + " first_number = second_number\n", + " second_number = result" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bScJ-6tULNW3" + }, + "source": [ + "If you managed it till here great job!\n", + "Is seems to work great so far, but you need to store these numbers so you can reference them when needed." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1VhirrXpLNW3" + }, + "source": [ + "Create an empty ***array*** called `fibonacci` and then append the elements of the sequence to it." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "thTMoVY2LNW3" + }, + "source": [ + "# Starting Point\n", + "first_number = 0\n", + "second_number = 1\n", + "\n", + "fibonacci = []\n", + "\n", + "fibonacci.append(first_number)\n", + "fibonacci.append(second_number)\n", + "\n", + "for count in range(20):\n", + " result = first_number + second_number\n", + " # print(result)\n", + " fibonacci.append(result)\n", + " first_number = second_number\n", + " second_number = result\n", + " \n", + "print(fibonacci)" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6nlc_cC7LNW5" + }, + "source": [ + "If everything worked according to the plan, you should be able to access any of the first 20 elements of the Fibonacci sequence at will.\n", + "\n", + "eg `fibonacci[0]` would get us the first item in the array whilst `fibonacci[9]` would get us the tenth item (remember Python is 0 based so you always need to take 1 away from the number you need)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "yEKa7pAuLNW6" + }, + "source": [ + "fibonacci[0]" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "1wbxOVnELNW7" + }, + "source": [ + "fibonacci[9]" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "50FpCM7CLNW9" + }, + "source": [ + "So now you know how to get at the index, you need to know which index values are asked for by the user.\n", + "Lets get some input from the user." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "YIJRBUXWLNW-", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 53 + }, + "outputId": "aaadcdb4-2317-4b63-c306-3256393a1875" + }, + "source": [ + "input()" + ], + "execution_count": null, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'2'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 12 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Get the first index from the user" + ], + "metadata": { + "id": "5Vp9iO2r2e2S" + } + }, + { + "cell_type": "code", + "source": [ + "first_index = input()" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "Zj6mnXCI2mNo", + "outputId": "8404c9dd-b5f0-42ec-97bd-d57abebafbed" + }, + "execution_count": null, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Get the second index from the user" + ], + "metadata": { + "id": "9LDXbzP02rFa" + } + }, + { + "cell_type": "code", + "metadata": { + "id": "wqbTuR2TLNXA", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "66aecb44-52c6-44f3-95a7-140c1dce6fe1" + }, + "source": [ + "second_index = input()" + ], + "execution_count": null, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Print the received inputs and their types" + ], + "metadata": { + "id": "EK9FMjJV22x9" + } + }, + { + "cell_type": "code", + "metadata": { + "id": "xfy81HrsLNXC", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "fd3d4b7d-88c7-4e1e-9486-3a0718dfa737" + }, + "source": [ + "print(first_index)\n", + "print(type(first_index))\n", + "print(second_index)\n", + "print(type(second_index))" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "2\n", + "\n", + "2\n", + "\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ttb_0MejLNXE" + }, + "source": [ + "The value received from input will be treated as a string type, you need to convert this to a number so python knows to treat it as one." + ] + }, + { + "cell_type": "code", + "source": [ + "first_index = int(first_index)\n", + "second_index = int(second_index)" + ], + "metadata": { + "id": "RwVoHTLn6QvB" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Print the type of the transformed variables." + ], + "metadata": { + "id": "pxKx8gKy2-eh" + } + }, + { + "cell_type": "code", + "source": [ + "type(first_index)\n", + "type(second_index)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dN_EzHKr3GmO", + "outputId": "c45cdbad-5e51-457a-83d5-57e92e2b44c4" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "int" + ] + }, + "metadata": {}, + "execution_count": 11 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CRuAEA7KLNXE" + }, + "source": [ + "Now you have all the parts you need to make this work. \n", + "\n", + "* The user should be prompted \"How many results would you like?\"\n", + "* The program should read the users preference, e.g. 20, and then compute the list of elements up to this number.\n", + "* Then the program should ask the user for 2 indexes within the list of the calculated Fibonacci sequence\n", + "* Finally it should print the summation of their values.\n", + "\n", + "Time to put it together:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ukW0WUA7LNXE", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "f1d134d8-61f7-4f93-a54b-d63dffe08964" + }, + "source": [ + "# Starting Point\n", + "first_number = 0\n", + "second_number = 1\n", + "\n", + "fibonacci = []\n", + "\n", + "fibonacci.append(first_number)\n", + "fibonacci.append(second_number)\n", + "\n", + "print(\"##### GENERATING FIBONACCI LIST #####\")\n", + "fib_range = int(input(\"How many results would you like?\"))\n", + "for count in range(fib_range-2):\n", + " result = first_number + second_number\n", + " # print(result)\n", + " fibonacci.append(result)\n", + " first_number = second_number\n", + " second_number = result\n", + "\n", + "print(\"##### COMPLETED MAKING FIBONACCI LIST #####\")\n", + "\n", + "\n", + "first_index = int(input(\"Please enter the first number you require?\"))\n", + "second_index = int(input(\"Please enter the second number you require?\"))\n", + "\n", + "print(\"##### GETTING RESULT #####\")\n", + "final_answer = fibonacci[first_index-1] + fibonacci[second_index-1]\n", + "print(\"\\n\\nThe answer is:\\n\\n{}\".format(final_answer))" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "##### GENERATING FIBONACCI LIST #####\n", + "How many results would you like?10\n", + "##### COMPLETED MAKING FIBONACCI LIST #####\n", + "Please enter the first number you require?10\n", + "Please enter the second number you require?9\n", + "##### GETTING RESULT #####\n", + "\n", + "\n", + "The answer is:\n", + "\n", + "55\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Finally plot the first 30 elements of the Fibonacci sequence using matplotlib" + ], + "metadata": { + "id": "qqMN0OEjEyPN" + } + }, + { + "cell_type": "code", + "metadata": { + "id": "edzR_wahLNXG", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 282 + }, + "outputId": "bb9ad5f3-811d-4687-adb0-432d3ed72ab9" + }, + "source": [ + "import matplotlib.pyplot as plt\n", + "plt.plot(fibonacci)" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[]" + ] + }, + "metadata": {}, + "execution_count": 13 + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "
" + ], + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUA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IzPrRcO/1IcA/YEUM/tqsKnCLxYKXDdPbsTMkmgo76fd/cWg8wRsCvB5M9tJw9La1Wb2VLCRArUX2Ovun/yr7AUaCr0juhYocPcSd68BXgQmB5wp7GKhwHXz5BAzMxrWNze5+8NB5wmau/+ju2e7ew4Nvy/ecve4O8tqKXc/AOwxs5GhTdcAGwOMFKTdwKVm1i305+Ya4vAF3TbdE7M96ObJp5gC3AmsM7PVoW0Phu5NKgLwbeDp0MnODuDrAecJhLuvMLMXgJU0XL21ijgcqdcovYhIjIqFJRQRETkNFbiISIxSgYuIxCgVuIhIjFKBi4jEKBW4iEiMUoGLiMSo/w+Ze+IJere6twAAAABJRU5ErkJggg==\n" + }, + "metadata": { + "needs_background": "light" + } + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Compute the Fibonacci sequence recursively" + ], + "metadata": { + "id": "AA67da2KzQnL" + } + }, + { + "cell_type": "code", + "source": [ + "def fibonacci_recursive(n):\n", + " if n < 2:\n", + " return n\n", + " return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2)" + ], + "metadata": { + "id": "jJppjtZAzT80" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "print(\"##### GENERATING FIBONACCI LIST #####\")\n", + "fib_range = int(input(\"How many results would you like?\"))\n", + "for i in range(fib_range):\n", + " print(fibonacci_recursive(i))" + ], + "metadata": { + "id": "1GDrTgOhz7TM", + "outputId": "c1007637-9156-417d-f973-77a3577857a2", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "##### GENERATING FIBONACCI LIST #####\n", + "How many results would you like?20\n", + "0\n", + "1\n", + "1\n", + "2\n", + "3\n", + "5\n", + "8\n", + "13\n", + "21\n", + "34\n", + "55\n", + "89\n", + "144\n", + "233\n", + "377\n", + "610\n", + "987\n", + "1597\n", + "2584\n", + "4181\n" + ] + } + ] + } + ] +} \ No newline at end of file