Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution For Problem 47 of Project Euler(Issue #15) #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions euler47.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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)


'''

#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]

'''


def prime_factors(prime, n):
factors = []
for i in prime:
if n%i == 0:
factors.append(i)
return factors


'''

#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]

'''


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())