From cd198b590f9f9fd78451ad68746e3717782419bb Mon Sep 17 00:00:00 2001 From: AmanPriyanshu <51470735+AmanPriyanshu@users.noreply.github.com> Date: Fri, 4 Oct 2019 00:18:15 +0530 Subject: [PATCH 1/2] Solution For Problem 47 of Project Euler(Issue #15) --- Euler47.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Euler47.py diff --git a/Euler47.py b/Euler47.py new file mode 100644 index 0000000..f5fe5eb --- /dev/null +++ b/Euler47.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[27]: + + +def prime_no_collector(prime, n): + if n == 1: #checking whether n == 1, not appending if it is equal as 1 is not a prime number + return prime + for i in range(2, int(n**0.5)+1): #Running loop from 2 to sq_root(n) to check whether the number is prime or not + if n%i == 0: #checking whether the numbe ris divisble or not (if divisible then it isn't a prime) + return prime #if not prime then returning the array without appending + return prime.append(n) + + + +# In[33]: + + +''' + +#Testing the prime_no_collector function +prime = [] +for i in range(1,20): + prime_no_collector(prime,i) +print(prime) +#Excpected Output: 2, 3, 5, 7, 11, 13, 17, 19 +#Function Output: [2, 3, 5, 7, 11, 13, 17, 19] + +''' + + +# In[34]: + + +def prime_factors(prime, n): + factors = [] + for i in prime: + if n%i == 0: + factors.append(i) + return factors + + +# In[38]: + + +''' + +#Testing function prime_factors: +print(prime_factors(prime, 15)) +print(prime_factors(prime, 17)) +print(prime_factors(prime, 14)) + +#Expected Output: [3, 5] [17] [2, 7] +#Function Output: [3, 5] +# [17] +# [2, 7] + +''' + + +# In[45]: + + +def main(): + prime = [] + answer = 0 + for i in range(1,1000000): #looping till 1,000,000 + prime_no_collector(prime,i) #collecting all prime numbers as we iterate + if len(prime_factors(prime, i)) == 4 and len(prime_factors(prime, i+1)) == 4 and len(prime_factors(prime, i+2)) == 4 and len(prime_factors(prime, i+3)) == 4: + return i +print(main()) + + +# In[ ]: + + + + From ea13b06f882596f332c054becea63d1af13f51ca Mon Sep 17 00:00:00 2001 From: AmanPriyanshu <51470735+AmanPriyanshu@users.noreply.github.com> Date: Fri, 4 Oct 2019 12:15:02 +0530 Subject: [PATCH 2/2] Rename pe047.py to euler47.py --- Euler47.py => euler47.py | 26 -------------------------- 1 file changed, 26 deletions(-) rename Euler47.py => euler47.py (93%) diff --git a/Euler47.py b/euler47.py similarity index 93% rename from Euler47.py rename to euler47.py index f5fe5eb..bf193cc 100644 --- a/Euler47.py +++ b/euler47.py @@ -1,9 +1,3 @@ -#!/usr/bin/env python -# coding: utf-8 - -# In[27]: - - def prime_no_collector(prime, n): if n == 1: #checking whether n == 1, not appending if it is equal as 1 is not a prime number return prime @@ -13,10 +7,6 @@ def prime_no_collector(prime, n): return prime.append(n) - -# In[33]: - - ''' #Testing the prime_no_collector function @@ -30,9 +20,6 @@ def prime_no_collector(prime, n): ''' -# In[34]: - - def prime_factors(prime, n): factors = [] for i in prime: @@ -41,9 +28,6 @@ def prime_factors(prime, n): return factors -# In[38]: - - ''' #Testing function prime_factors: @@ -59,9 +43,6 @@ def prime_factors(prime, n): ''' -# In[45]: - - def main(): prime = [] answer = 0 @@ -70,10 +51,3 @@ def main(): if len(prime_factors(prime, i)) == 4 and len(prime_factors(prime, i+1)) == 4 and len(prime_factors(prime, i+2)) == 4 and len(prime_factors(prime, i+3)) == 4: return i print(main()) - - -# In[ ]: - - - -