Automatic commit performed through alias...
This commit is contained in:
@@ -14,6 +14,51 @@
|
||||
import decorators # Typically imported to compute execution duration of functions.
|
||||
import time # Typically imported for sleep function, to slow down execution in terminal.
|
||||
import typing
|
||||
import pprint
|
||||
|
||||
# Create function that finds the next
|
||||
# prime number when supplied with an
|
||||
# intitial integer.
|
||||
|
||||
def primes_gen(start_n: int,max_n: int):
|
||||
"""
|
||||
Returns a generator object, containing the
|
||||
primes inside a specified range.
|
||||
primes_gen(start_n,max_n)
|
||||
param 'start_n': Previous prime.
|
||||
param 'max_n': Maximum
|
||||
"""
|
||||
start_n += 1
|
||||
for candidate in range(start_n,max_n):
|
||||
notPrime = False
|
||||
|
||||
if candidate in [0,1,2,3]:
|
||||
yield candidate
|
||||
for dividend in range(2,candidate):
|
||||
|
||||
if candidate%dividend == 0:
|
||||
notPrime = True
|
||||
|
||||
if not notPrime:
|
||||
yield candidate
|
||||
|
||||
|
||||
def find_prime_factors(n: int):
|
||||
"""
|
||||
Return a list object containing all
|
||||
prime factors of the provided integer, n.
|
||||
|
||||
find_prime_factors(n)
|
||||
|
||||
param 'n': The integer to be analyzed.
|
||||
|
||||
"""
|
||||
|
||||
returned_prime = list(primes_gen(0,n))
|
||||
pprint.pprint(returned_prime)
|
||||
|
||||
return returned_prime
|
||||
|
||||
|
||||
def evenly_divisible(candidate: int,factors: list):
|
||||
"""
|
||||
@@ -43,25 +88,50 @@ def main():
|
||||
|
||||
# Receive problem inputs...
|
||||
smallest_factor = 1
|
||||
largest_factor = 17
|
||||
largest_factor = 5
|
||||
|
||||
# Compute intermediate inputs
|
||||
factor_list = [int(i) for i in range(smallest_factor,largest_factor+1)]
|
||||
maximum_solution_bound = 1
|
||||
for f in factor_list:
|
||||
maximum_solution_bound *= f
|
||||
common = []
|
||||
product = 1
|
||||
|
||||
# Initialize loop parameters
|
||||
n = 10
|
||||
test_passed = False
|
||||
#
|
||||
# Brute force method below breaks down
|
||||
# and doesn't scale well ...
|
||||
#
|
||||
# # Initialize loop parameters
|
||||
# n = 1
|
||||
# test_passed = False
|
||||
#
|
||||
# while n<maximum_solution_bound and not test_passed:
|
||||
# test_passed = evenly_divisible(n,factor_list)
|
||||
# if not test_passed:
|
||||
# n += 1
|
||||
|
||||
while n<maximum_solution_bound and not test_passed:
|
||||
test_passed = evenly_divisible(n,factor_list)
|
||||
if not test_passed:
|
||||
n += 1
|
||||
# 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.
|
||||
|
||||
|
||||
pprint.pprint(factor_list)
|
||||
|
||||
print("The largest palindrome number which is a product of two numbers of length {} is {} ... ".format(factor_list,n))
|
||||
for i in factor_list:
|
||||
common.append(find_prime_factors(i))
|
||||
|
||||
pprint.pprint(common)
|
||||
|
||||
for j in common:
|
||||
for k in j:
|
||||
product *= k
|
||||
|
||||
print(product)
|
||||
|
||||
# print("The largest palindrome number which is a product of two numbers of length {} is {} ... ".format("foo_list","foo"))
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user