{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 5:\n", "\n", "[Euler Project #5](https://projecteuler.net/problem=5)\n", "\n", "> *2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.*\n", "> *What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?*\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reserved Space For Imports\n", "---" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pprint\n", "import time # Typically imported for sleep function, to slow down execution in terminal.\n", "import typing\n", "import decorators # Typically imported to compute execution duration of functions.\n", "import numpy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reserved Space For Method Definition\n", "---" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def primes_gen(start_n: int,max_n: int):\n", " \"\"\"\n", " Returns a generator object, containing the \n", " primes inside a specified range.\n", " primes_gen(start_n,max_n)\n", " param 'start_n': Previous prime.\n", " param 'max_n': Maximum integer allowed to be returned. Quit if reached.\n", " \"\"\"\n", " start_n += 1\n", " for candidate in range(start_n,max_n):\n", " notPrime = False\n", " \n", " if candidate in [0,1,2,3]:\n", " yield candidate\n", " for dividend in range(2,candidate):\n", " \n", " if candidate%dividend == 0:\n", " notPrime = True\n", " \n", " if not notPrime:\n", " yield candidate" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def evenly_divisible(candidate: int,factors: list):\n", " \"\"\"\n", " Determines if the supplied integer candidate is \n", " evenly divisble by the supplied list of factors.\n", " \n", " evenly_divisible(candidate: int, factors: list)\n", "\n", " param 'candidate': Integer to be tested.\n", " param 'factors': List of factors for the modulus operator.\n", " \n", " \"\"\"\n", " \n", " modulus_sum = 0\n", "\n", " for n in factors:\n", " modulus_sum += candidate%n\n", " \n", " if modulus_sum == 0: \n", " return True\n", " else:\n", " return False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Begin with testing the problem statement's example case.\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Mathematically, the trick is to recognize that this a LCM (Least Common Multiple) problem. The solution is list all the prime factors of each number in the factor list, then compute their collective product.*\n", "\n", " - [x] Create the list of factors, prescribed by the problem statement. Use a list.\n", " - [ ] Generate a list of prime factors for each of the factors. Use a list of list.\n", " - [ ] For each of the unique prime factors found in the previous list of lists, \n", " find the factor for which the \n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Receive problem inputs...\n", "smallest_factor = 1\n", "largest_factor = 10\n", "\n", "# Compute intermediate inputs\n", "factor_list = [int(i) for i in range(smallest_factor,largest_factor+1)]\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.2" } }, "nbformat": 4, "nbformat_minor": 4 }