update primefac func name

This commit is contained in:
Andrew Macmillan 2021-01-30 13:42:27 +00:00
parent 10df6f8625
commit 12db9a813e
1 changed files with 12 additions and 12 deletions

View File

@ -9,16 +9,17 @@ from time import time
def calculatePrimeFactors(n):
primfac = []
prime_factors = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d) # supposing you want multiple factors repeated
# supposing you want multiple factors repeated
prime_factors.append(d)
n //= d
d += 1
if n > 1:
primfac.append(n)
return primfac
prime_factors.append(n)
return prime_factors
# Sequential Example
@ -34,7 +35,6 @@ def seq_crunch():
return f'{t1-t0:.2f}'
# Multi-processing Example
@ -60,11 +60,11 @@ def multi_proc_crunch():
t1 = time()
return f'{t1-t0:.2f}'
if __name__ == '__main__':
seq_time = seq_crunch()
multi_proc_time = multi_proc_crunch()
print('\n==================================')
print(f'Time to crunch prime factors sequentially: {seq_time}s')
print(f'Time to crunch prime factors using multi-processing: {multi_proc_time}s')
print(f'Crunch prime factors sequentially: {seq_time}s')
print(f'Crunch prime factors using multi-processing: {multi_proc_time}s')
print('==================================')