From 60e52c6abffbbe34206d78858b4da823a0a21a7e Mon Sep 17 00:00:00 2001 From: Shaun Setlock Date: Fri, 24 Apr 2020 23:49:50 -0400 Subject: [PATCH] Automatic commit performed through alias... --- problems/005_problem.py | 88 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 9 deletions(-) diff --git a/problems/005_problem.py b/problems/005_problem.py index b9b9e28..7c88ce6 100755 --- a/problems/005_problem.py +++ b/problems/005_problem.py @@ -14,7 +14,52 @@ 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): """ Determines if the supplied integer candidate is @@ -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 + +# +# Brute force method below breaks down +# and doesn't scale well ... +# +# # Initialize loop parameters +# n = 1 +# test_passed = False +# +# while n