@@ -51,6 +51,32 @@ def find_primes(upper_bound):
51
51
return primes
52
52
53
53
54
+ def prime_factors (num ):
55
+ """
56
+ Finds the smallest primes that divide a number.
57
+ For unique primes, turn the list into a set.
58
+ Example: 120 / 2 = 60
59
+ 60 / 2 = 30
60
+ 30 / 2 = 15
61
+ 15 / 3 = 5
62
+ 5 is prime.
63
+ returns [2, 2, 2, 3, 5]
64
+ """
65
+ primes = find_primes (int (math .sqrt (num + 1 ))) # Finds all primes that might be a factor
66
+ factors = []
67
+
68
+ for prime in primes :
69
+
70
+ if prime >= num + 1 : # If prime is bigger than the number, it is no longer divisible
71
+ break # So for long lists, quitting earlier is faster
72
+
73
+ while num % prime == 0 :
74
+ num = num // prime # Divides the number by the prime, so that we can see how many times
75
+ factors .append (prime ) # a number is divisible by a prime
76
+
77
+ return factors
78
+
79
+
54
80
def factorial (num ):
55
81
"""
56
82
The factorial of a number.
@@ -67,6 +93,29 @@ def factorial(num):
67
93
return product
68
94
69
95
96
+ def zeros (dimensions ):
97
+ """
98
+ Attempted clone of numpy zeros.
99
+ Not as quick, but might be useful if long lists are desired
100
+ and numpy not available.
101
+ """
102
+ x = y = None
103
+ try :
104
+ y , x = dimensions # If it cannot unpack it as tuple, it will fail
105
+ except TypeError :
106
+ x = dimensions # If it fails, it will standard to 1 row
107
+ y = 1
108
+
109
+ zeros = []
110
+ if y == 1 :
111
+ zeros += [0 ]* x
112
+ else :
113
+ for row in range (y ): # Makes rows with columns of 0
114
+ zeros .append ([0 ]* x )
115
+
116
+ return zeros
117
+
118
+
70
119
def louville_distance (precision ):
71
120
"""
72
121
Finds the distance between in zeroes between 2 '1's in the
0 commit comments