Automatic commit performed through alias...

This commit is contained in:
Shaun Setlock
2020-05-30 19:10:39 -04:00
parent 925cb57d70
commit 46960540a2
6 changed files with 865 additions and 6 deletions

View File

@@ -4,16 +4,27 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Problem 5:\n",
"# 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",
"[Euler Project #5](https://projecteuler.net/problem=5)\n",
"\n",
"What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?\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": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -25,6 +36,134 @@
"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,