diff --git a/arithmetic_analysis/bisection.py b/arithmetic_analysis/bisection.py index 78582b025880..fa6994a5dfc9 100644 --- a/arithmetic_analysis/bisection.py +++ b/arithmetic_analysis/bisection.py @@ -19,7 +19,7 @@ def bisection( return else: mid = start + (end - start) / 2.0 - while abs(start - mid) > 10 ** -7: # until we achieve precise equals to 10^-7 + while abs(start - mid) > 10**-7: # until we achieve precise equals to 10^-7 if function(mid) == 0: return mid elif function(mid) * function(start) < 0: diff --git a/arithmetic_analysis/in_static_equilibrium.py b/arithmetic_analysis/in_static_equilibrium.py index addaff888f7f..4be2c187c630 100644 --- a/arithmetic_analysis/in_static_equilibrium.py +++ b/arithmetic_analysis/in_static_equilibrium.py @@ -27,7 +27,7 @@ def polar_force( def in_static_equilibrium( - forces: array, location: array, eps: float = 10 ** -1 + forces: array, location: array, eps: float = 10**-1 ) -> bool: """ Check if a system is in equilibrium. diff --git a/arithmetic_analysis/intersection.py b/arithmetic_analysis/intersection.py index 0fdcfbf1943e..099e8c2950e3 100644 --- a/arithmetic_analysis/intersection.py +++ b/arithmetic_analysis/intersection.py @@ -10,7 +10,7 @@ def intersection( x_n2 = x_n1 - ( function(x_n1) / ((function(x_n1) - function(x_n)) / (x_n1 - x_n)) ) - if abs(x_n2 - x_n1) < 10 ** -5: + if abs(x_n2 - x_n1) < 10**-5: return x_n2 x_n = x_n1 x_n1 = x_n2 diff --git a/arithmetic_analysis/newton_method.py b/arithmetic_analysis/newton_method.py index 1408a983041d..cf5649ee3f3b 100644 --- a/arithmetic_analysis/newton_method.py +++ b/arithmetic_analysis/newton_method.py @@ -8,17 +8,17 @@ def newton(function, function1, startingInt): x_n = startingInt while True: x_n1 = x_n - function(x_n) / function1(x_n) - if abs(x_n - x_n1) < 10 ** -5: + if abs(x_n - x_n1) < 10**-5: return x_n1 x_n = x_n1 def f(x): - return (x ** 3) - (2 * x) - 5 + return (x**3) - (2 * x) - 5 def f1(x): - return 3 * (x ** 2) - 2 + return 3 * (x**2) - 2 if __name__ == "__main__": diff --git a/arithmetic_analysis/newton_raphson.py b/arithmetic_analysis/newton_raphson.py index 60c56ed30e75..d9130c7c2b41 100644 --- a/arithmetic_analysis/newton_raphson.py +++ b/arithmetic_analysis/newton_raphson.py @@ -8,7 +8,7 @@ from sympy import diff -def newton_raphson(func: str, a: int, precision: int = 10 ** -10) -> float: +def newton_raphson(func: str, a: int, precision: int = 10**-10) -> float: """Finds root from the point 'a' onwards by Newton-Raphson method >>> newton_raphson("sin(x)", 2) 3.1415926536808043 diff --git a/ciphers/deterministic_miller_rabin.py b/ciphers/deterministic_miller_rabin.py index e604a7b84166..bfc576f65c64 100644 --- a/ciphers/deterministic_miller_rabin.py +++ b/ciphers/deterministic_miller_rabin.py @@ -73,7 +73,7 @@ def miller_rabin(n, allow_probable=False): for prime in plist: pr = False for r in range(s): - m = pow(prime, d * 2 ** r, n) + m = pow(prime, d * 2**r, n) # see article for analysis explanation for m if (r == 0 and m == 1) or ((m + 1) % n == 0): pr = True diff --git a/ciphers/rabin_miller.py b/ciphers/rabin_miller.py index c544abdf9acc..9c0812a8fe8e 100644 --- a/ciphers/rabin_miller.py +++ b/ciphers/rabin_miller.py @@ -21,7 +21,7 @@ def rabinMiller(num): return False else: i = i + 1 - v = (v ** 2) % num + v = (v**2) % num return True diff --git a/ciphers/rsa_cipher.py b/ciphers/rsa_cipher.py index 371966b8379b..5b2ba68f95c8 100644 --- a/ciphers/rsa_cipher.py +++ b/ciphers/rsa_cipher.py @@ -58,8 +58,8 @@ def getTextFromBlocks(blockInts, messageLength, blockSize=DEFAULT_BLOCK_SIZE): blockMessage = [] for i in range(blockSize - 1, -1, -1): if len(message) + i < messageLength: - asciiNumber = blockInt // (BYTE_SIZE ** i) - blockInt = blockInt % (BYTE_SIZE ** i) + asciiNumber = blockInt // (BYTE_SIZE**i) + blockInt = blockInt % (BYTE_SIZE**i) blockMessage.insert(0, chr(asciiNumber)) message.extend(blockMessage) return "".join(message) diff --git a/ciphers/rsa_factorization.py b/ciphers/rsa_factorization.py index 9ec34e6c5a17..8daaa3b50a8c 100644 --- a/ciphers/rsa_factorization.py +++ b/ciphers/rsa_factorization.py @@ -39,7 +39,7 @@ def rsafactor(d: int, e: int, N: int) -> List[int]: while True: if t % 2 == 0: t = t // 2 - x = (g ** t) % N + x = (g**t) % N y = math.gcd(x - 1, N) if x > 1 and y > 1: p = y diff --git a/computer_vision/harriscorner.py b/computer_vision/harriscorner.py index 35302f01411b..63e6cf12ff24 100644 --- a/computer_vision/harriscorner.py +++ b/computer_vision/harriscorner.py @@ -39,8 +39,8 @@ def detect(self, img_path: str): color_img = img.copy() color_img = cv2.cvtColor(color_img, cv2.COLOR_GRAY2RGB) dy, dx = np.gradient(img) - ixx = dx ** 2 - iyy = dy ** 2 + ixx = dx**2 + iyy = dy**2 ixy = dx * dy k = 0.04 offset = self.window_size // 2 @@ -56,9 +56,9 @@ def detect(self, img_path: str): y - offset : y + offset + 1, x - offset : x + offset + 1 ].sum() - det = (wxx * wyy) - (wxy ** 2) + det = (wxx * wyy) - (wxy**2) trace = wxx + wyy - r = det - k * (trace ** 2) + r = det - k * (trace**2) # Can change the value if r > 0.5: corner_list.append([x, y, r]) diff --git a/digital_image_processing/index_calculation.py b/digital_image_processing/index_calculation.py index 4350b8603390..033334af8a2a 100644 --- a/digital_image_processing/index_calculation.py +++ b/digital_image_processing/index_calculation.py @@ -203,7 +203,7 @@ def CVI(self): https://www.indexdatabase.de/db/i-single.php?id=391 :return: index """ - return self.nir * (self.red / (self.green ** 2)) + return self.nir * (self.red / (self.green**2)) def GLI(self): """ @@ -295,7 +295,7 @@ def ATSAVI(self, X=0.08, a=1.22, b=0.03): """ return a * ( (self.nir - a * self.red - b) - / (a * self.nir + self.red - a * b + X * (1 + a ** 2)) + / (a * self.nir + self.red - a * b + X * (1 + a**2)) ) def BWDRVI(self): @@ -363,7 +363,7 @@ def GEMI(self): https://www.indexdatabase.de/db/i-single.php?id=25 :return: index """ - n = (2 * (self.nir ** 2 - self.red ** 2) + 1.5 * self.nir + 0.5 * self.red) / ( + n = (2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / ( self.nir + self.red + 0.5 ) return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red) diff --git a/graphics/bezier_curve.py b/graphics/bezier_curve.py index 512efadf86ee..88757b9503af 100644 --- a/graphics/bezier_curve.py +++ b/graphics/bezier_curve.py @@ -40,7 +40,7 @@ def basis_function(self, t: float) -> List[float]: for i in range(len(self.list_of_points)): # basis function for each i output_values.append( - comb(self.degree, i) * ((1 - t) ** (self.degree - i)) * (t ** i) + comb(self.degree, i) * ((1 - t) ** (self.degree - i)) * (t**i) ) # the basis must sum up to 1 for it to produce a valid Bezier curve. assert round(sum(output_values), 5) == 1 diff --git a/graphs/bidirectional_a_star.py b/graphs/bidirectional_a_star.py index 76313af769be..5b012f6197cc 100644 --- a/graphs/bidirectional_a_star.py +++ b/graphs/bidirectional_a_star.py @@ -58,7 +58,7 @@ def calculate_heuristic(self) -> float: if HEURISTIC == 1: return abs(dx) + abs(dy) else: - return sqrt(dy ** 2 + dx ** 2) + return sqrt(dy**2 + dx**2) def __lt__(self, other) -> bool: return self.f_cost < other.f_cost diff --git a/hashes/chaos_machine.py b/hashes/chaos_machine.py index 1bdf984b68de..3fcfaa5c6599 100644 --- a/hashes/chaos_machine.py +++ b/hashes/chaos_machine.py @@ -62,8 +62,8 @@ def xorshift(X, Y): params_space[key] = (machine_time * 0.01 + r * 1.01) % 1 + 3 # Choosing Chaotic Data - X = int(buffer_space[(key + 2) % m] * (10 ** 10)) - Y = int(buffer_space[(key - 2) % m] * (10 ** 10)) + X = int(buffer_space[(key + 2) % m] * (10**10)) + Y = int(buffer_space[(key - 2) % m] * (10**10)) # Machine Time machine_time += 1 diff --git a/hashes/hamming_code.py b/hashes/hamming_code.py index 14d23ef3cef4..508cf98bfe21 100644 --- a/hashes/hamming_code.py +++ b/hashes/hamming_code.py @@ -78,7 +78,7 @@ def emitterConverter(sizePar, data): >>> emitterConverter(4, "101010111111") ['1', '1', '1', '1', '0', '1', '0', '0', '1', '0', '1', '1', '1', '1', '1', '1'] """ - if sizePar + len(data) <= 2 ** sizePar - (len(data) - 1): + if sizePar + len(data) <= 2**sizePar - (len(data) - 1): print("ERROR - size of parity don't match with size of data") exit(0) diff --git a/hashes/md5.py b/hashes/md5.py index 09a93e70a1b8..fee7e010ff15 100644 --- a/hashes/md5.py +++ b/hashes/md5.py @@ -95,7 +95,7 @@ def not32(i): def sum32(a, b): """ """ - return (a + b) % 2 ** 32 + return (a + b) % 2**32 def leftrot32(i, s): @@ -115,7 +115,7 @@ def md5me(testString): bs += format(ord(i), "08b") bs = pad(bs) - tvals = [int(2 ** 32 * abs(math.sin(i + 1))) for i in range(64)] + tvals = [int(2**32 * abs(math.sin(i + 1))) for i in range(64)] a0 = 0x67452301 b0 = 0xEFCDAB89 @@ -212,7 +212,7 @@ def md5me(testString): dtemp = D D = C C = B - B = sum32(B, leftrot32((A + f + tvals[i] + m[g]) % 2 ** 32, s[i])) + B = sum32(B, leftrot32((A + f + tvals[i] + m[g]) % 2**32, s[i])) A = dtemp a0 = sum32(a0, A) b0 = sum32(b0, B) diff --git a/linear_algebra/src/lib.py b/linear_algebra/src/lib.py index 353c8334093b..e666d91210f9 100644 --- a/linear_algebra/src/lib.py +++ b/linear_algebra/src/lib.py @@ -93,7 +93,7 @@ def euclidLength(self): """ summe = 0 for c in self.__components: - summe += c ** 2 + summe += c**2 return math.sqrt(summe) def __add__(self, other): diff --git a/machine_learning/k_means_clust.py b/machine_learning/k_means_clust.py index 8db0275ebcc2..12008d4e9326 100644 --- a/machine_learning/k_means_clust.py +++ b/machine_learning/k_means_clust.py @@ -117,7 +117,7 @@ def compute_heterogeneity(data, k, centroids, cluster_assignment): distances = pairwise_distances( member_data_points, [centroids[i]], metric="euclidean" ) - squared_distances = distances ** 2 + squared_distances = distances**2 heterogeneity += np.sum(squared_distances) return heterogeneity diff --git a/machine_learning/sequential_minimum_optimization.py b/machine_learning/sequential_minimum_optimization.py index a0b99a788cbd..3f91c8be385e 100644 --- a/machine_learning/sequential_minimum_optimization.py +++ b/machine_learning/sequential_minimum_optimization.py @@ -339,15 +339,15 @@ def _get_new_alpha(self, i1, i2, a1, a2, e1, e2, y1, y2): ol = ( l1 * f1 + L * f2 - + 1 / 2 * l1 ** 2 * K(i1, i1) - + 1 / 2 * L ** 2 * K(i2, i2) + + 1 / 2 * l1**2 * K(i1, i1) + + 1 / 2 * L**2 * K(i2, i2) + s * L * l1 * K(i1, i2) ) oh = ( h1 * f1 + H * f2 - + 1 / 2 * h1 ** 2 * K(i1, i1) - + 1 / 2 * H ** 2 * K(i2, i2) + + 1 / 2 * h1**2 * K(i1, i1) + + 1 / 2 * H**2 * K(i2, i2) + s * H * h1 * K(i1, i2) ) """ diff --git a/maths/area_under_curve.py b/maths/area_under_curve.py index 2d01e414b63b..3f6629768c8c 100644 --- a/maths/area_under_curve.py +++ b/maths/area_under_curve.py @@ -49,7 +49,7 @@ def trapezoidal_area( if __name__ == "__main__": def f(x): - return x ** 3 + x ** 2 + return x**3 + x**2 print("f(x) = x^3 + x^2") print("The area between the curve, x = -5, x = 5 and the x axis is:") diff --git a/maths/armstrong_numbers.py b/maths/armstrong_numbers.py index d30ed2e430a0..8c75a6ce9a1c 100644 --- a/maths/armstrong_numbers.py +++ b/maths/armstrong_numbers.py @@ -37,7 +37,7 @@ def armstrong_number(n: int) -> bool: temp = n while temp > 0: rem = temp % 10 - sum += rem ** number_of_digits + sum += rem**number_of_digits temp //= 10 return n == sum diff --git a/maths/basic_maths.py b/maths/basic_maths.py index 07ee3b3df296..6d1164ce7ecd 100644 --- a/maths/basic_maths.py +++ b/maths/basic_maths.py @@ -51,14 +51,14 @@ def sum_of_divisors(n: int) -> int: temp += 1 n = int(n / 2) if temp > 1: - s *= (2 ** temp - 1) / (2 - 1) + s *= (2**temp - 1) / (2 - 1) for i in range(3, int(math.sqrt(n)) + 1, 2): temp = 1 while n % i == 0: temp += 1 n = int(n / i) if temp > 1: - s *= (i ** temp - 1) / (i - 1) + s *= (i**temp - 1) / (i - 1) return int(s) diff --git a/maths/gaussian.py b/maths/gaussian.py index 48ce7abd0470..d1afeabf35f6 100644 --- a/maths/gaussian.py +++ b/maths/gaussian.py @@ -50,7 +50,7 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int: >>> gaussian(2523, mu=234234, sigma=3425) 0.0 """ - return 1 / sqrt(2 * pi * sigma ** 2) * exp(-((x - mu) ** 2) / 2 * sigma ** 2) + return 1 / sqrt(2 * pi * sigma**2) * exp(-((x - mu) ** 2) / 2 * sigma**2) if __name__ == "__main__": diff --git a/maths/karatsuba.py b/maths/karatsuba.py index df29c77a5cf2..b772c0d77039 100644 --- a/maths/karatsuba.py +++ b/maths/karatsuba.py @@ -14,8 +14,8 @@ def karatsuba(a, b): m1 = max(len(str(a)), len(str(b))) m2 = m1 // 2 - a1, a2 = divmod(a, 10 ** m2) - b1, b2 = divmod(b, 10 ** m2) + a1, a2 = divmod(a, 10**m2) + b1, b2 = divmod(b, 10**m2) x = karatsuba(a2, b2) y = karatsuba((a1 + a2), (b1 + b2)) diff --git a/maths/monte_carlo.py b/maths/monte_carlo.py index 28027cbe4178..efb6a01d57fd 100644 --- a/maths/monte_carlo.py +++ b/maths/monte_carlo.py @@ -20,7 +20,7 @@ def pi_estimator(iterations: int): """ # A local function to see if a dot lands in the circle. def is_in_circle(x: float, y: float) -> bool: - distance_from_centre = sqrt((x ** 2) + (y ** 2)) + distance_from_centre = sqrt((x**2) + (y**2)) # Our circle has a radius of 1, so a distance # greater than 1 would land outside the circle. return distance_from_centre <= 1 diff --git a/maths/numerical_integration.py b/maths/numerical_integration.py index 67fbc0ddbf30..f2733c541725 100644 --- a/maths/numerical_integration.py +++ b/maths/numerical_integration.py @@ -55,7 +55,7 @@ def trapezoidal_area( if __name__ == "__main__": def f(x): - return x ** 3 + return x**3 print("f(x) = x^3") print("The area between the curve, x = -10, x = 10 and the x axis is:") diff --git a/maths/pi_monte_carlo_estimation.py b/maths/pi_monte_carlo_estimation.py index 20b46dddc6e5..81be083787bd 100644 --- a/maths/pi_monte_carlo_estimation.py +++ b/maths/pi_monte_carlo_estimation.py @@ -11,7 +11,7 @@ def is_in_unit_circle(self) -> bool: True, if the point lies in the unit circle False, otherwise """ - return (self.x ** 2 + self.y ** 2) <= 1 + return (self.x**2 + self.y**2) <= 1 @classmethod def random_unit_square(cls): diff --git a/maths/polynomial_evaluation.py b/maths/polynomial_evaluation.py index d2394f398c36..ff061dafbf14 100644 --- a/maths/polynomial_evaluation.py +++ b/maths/polynomial_evaluation.py @@ -12,7 +12,7 @@ def evaluate_poly(poly: Sequence[float], x: float) -> float: >>> evaluate_poly((0.0, 0.0, 5.0, 9.3, 7.0), 10.0) 79800.0 """ - return sum(c * (x ** i) for i, c in enumerate(poly)) + return sum(c * (x**i) for i, c in enumerate(poly)) def horner(poly: Sequence[float], x: float) -> float: diff --git a/maths/radix2_fft.py b/maths/radix2_fft.py index de87071e5440..f75d81cbafa7 100644 --- a/maths/radix2_fft.py +++ b/maths/radix2_fft.py @@ -91,7 +91,7 @@ def __DFT(self, which): next_ncol = self.C_max_length // 2 while next_ncol > 0: new_dft = [[] for i in range(next_ncol)] - root = self.root ** next_ncol + root = self.root**next_ncol # First half of next step current_root = 1 diff --git a/maths/segmented_sieve.py b/maths/segmented_sieve.py index c1cc497ad33e..b15ec2480678 100644 --- a/maths/segmented_sieve.py +++ b/maths/segmented_sieve.py @@ -48,4 +48,4 @@ def sieve(n): return prime -print(sieve(10 ** 6)) +print(sieve(10**6)) diff --git a/project_euler/problem_06/sol1.py b/project_euler/problem_06/sol1.py index 513b354679a9..996caeda41b1 100644 --- a/project_euler/problem_06/sol1.py +++ b/project_euler/problem_06/sol1.py @@ -31,9 +31,9 @@ def solution(n): suma = 0 sumb = 0 for i in range(1, n + 1): - suma += i ** 2 + suma += i**2 sumb += i - sum = sumb ** 2 - suma + sum = sumb**2 - suma return sum diff --git a/project_euler/problem_07/sol2.py b/project_euler/problem_07/sol2.py index ec182b835c84..903cec72f05e 100644 --- a/project_euler/problem_07/sol2.py +++ b/project_euler/problem_07/sol2.py @@ -8,7 +8,7 @@ def isprime(number): - for i in range(2, int(number ** 0.5) + 1): + for i in range(2, int(number**0.5) + 1): if number % i == 0: return False return True diff --git a/project_euler/problem_09/sol1.py b/project_euler/problem_09/sol1.py index 3bb5c968115d..b3e25db8408f 100644 --- a/project_euler/problem_09/sol1.py +++ b/project_euler/problem_09/sol1.py @@ -25,7 +25,7 @@ def solution(): for b in range(400): for c in range(500): if a < b < c: - if (a ** 2) + (b ** 2) == (c ** 2): + if (a**2) + (b**2) == (c**2): if (a + b + c) == 1000: return a * b * c diff --git a/project_euler/problem_10/sol3.py b/project_euler/problem_10/sol3.py index 739aaa9f16bb..78dfdf50ac61 100644 --- a/project_euler/problem_10/sol3.py +++ b/project_euler/problem_10/sol3.py @@ -41,7 +41,7 @@ def prime_sum(n: int) -> int: list_[0] = 1 list_[1] = 1 - for i in range(2, int(n ** 0.5) + 1): + for i in range(2, int(n**0.5) + 1): if list_[i] == 0: for j in range(i * i, n + 1, i): list_[j] = 1 diff --git a/project_euler/problem_12/sol1.py b/project_euler/problem_12/sol1.py index 7e080c4e45a1..4da13d572089 100644 --- a/project_euler/problem_12/sol1.py +++ b/project_euler/problem_12/sol1.py @@ -30,7 +30,7 @@ def count_divisors(n): if n % i == 0: nDivisors += 2 # check if n is perfect square - if n ** 0.5 == int(n ** 0.5): + if n**0.5 == int(n**0.5): nDivisors -= 1 return nDivisors diff --git a/project_euler/problem_12/sol2.py b/project_euler/problem_12/sol2.py index 5ff0d8349b90..25d7d3d865ad 100644 --- a/project_euler/problem_12/sol2.py +++ b/project_euler/problem_12/sol2.py @@ -29,7 +29,7 @@ def triangle_number_generator(): def count_divisors(n): - return sum([2 for i in range(1, int(n ** 0.5) + 1) if n % i == 0 and i * i != n]) + return sum([2 for i in range(1, int(n**0.5) + 1) if n % i == 0 and i * i != n]) def solution(): diff --git a/project_euler/problem_16/sol1.py b/project_euler/problem_16/sol1.py index 67c50ac87876..477b05b95fcc 100644 --- a/project_euler/problem_16/sol1.py +++ b/project_euler/problem_16/sol1.py @@ -16,7 +16,7 @@ def solution(power): >>> solution(15) 26 """ - num = 2 ** power + num = 2**power string_num = str(num) list_num = list(string_num) sum_of_num = 0 @@ -29,6 +29,6 @@ def solution(power): if __name__ == "__main__": power = int(input("Enter the power of 2: ").strip()) - print("2 ^ ", power, " = ", 2 ** power) + print("2 ^ ", power, " = ", 2**power) result = solution(power) print("Sum of the digits is: ", result) diff --git a/project_euler/problem_16/sol2.py b/project_euler/problem_16/sol2.py index cd724d89a9e3..4ab646e01801 100644 --- a/project_euler/problem_16/sol2.py +++ b/project_euler/problem_16/sol2.py @@ -17,7 +17,7 @@ def solution(power): >>> solution(15) 26 """ - n = 2 ** power + n = 2**power r = 0 while n: r, n = r + n % 10, n // 10 diff --git a/project_euler/problem_23/sol1.py b/project_euler/problem_23/sol1.py index a72b6123e3ee..83b85f3f721c 100644 --- a/project_euler/problem_23/sol1.py +++ b/project_euler/problem_23/sol1.py @@ -30,7 +30,7 @@ def solution(limit=28123): """ sumDivs = [1] * (limit + 1) - for i in range(2, int(limit ** 0.5) + 1): + for i in range(2, int(limit**0.5) + 1): sumDivs[i * i] += i for k in range(i + 1, limit // i + 1): sumDivs[k * i] += k + i diff --git a/project_euler/problem_27/problem_27_sol1.py b/project_euler/problem_27/problem_27_sol1.py index e4833574c509..b60dc5bf65d0 100644 --- a/project_euler/problem_27/problem_27_sol1.py +++ b/project_euler/problem_27/problem_27_sol1.py @@ -56,7 +56,7 @@ def solution(a_limit: int, b_limit: int) -> int: if is_prime(b): count = 0 n = 0 - while is_prime((n ** 2) + (a * n) + b): + while is_prime((n**2) + (a * n) + b): count += 1 n += 1 if count > longest[0]: diff --git a/project_euler/problem_28/sol1.py b/project_euler/problem_28/sol1.py index 11b48fea9adf..903caeddd12f 100644 --- a/project_euler/problem_28/sol1.py +++ b/project_euler/problem_28/sol1.py @@ -37,7 +37,7 @@ def diagonal_sum(n): for i in range(1, int(ceil(n / 2.0))): odd = 2 * i + 1 even = 2 * i - total = total + 4 * odd ** 2 - 6 * even + total = total + 4 * odd**2 - 6 * even return total diff --git a/project_euler/problem_29/solution.py b/project_euler/problem_29/solution.py index 4313a7b06392..fed8128f9f94 100644 --- a/project_euler/problem_29/solution.py +++ b/project_euler/problem_29/solution.py @@ -41,7 +41,7 @@ def solution(n): for a in range(2, N): for b in range(2, N): - currentPow = a ** b # calculates the current power + currentPow = a**b # calculates the current power collectPowers.add(currentPow) # adds the result to the set return len(collectPowers) diff --git a/project_euler/problem_48/sol1.py b/project_euler/problem_48/sol1.py index 06ad1408dcef..3f88fcecfc41 100644 --- a/project_euler/problem_48/sol1.py +++ b/project_euler/problem_48/sol1.py @@ -16,7 +16,7 @@ def solution(): """ total = 0 for i in range(1, 1001): - total += i ** i + total += i**i return str(total)[-10:] diff --git a/project_euler/problem_551/sol1.py b/project_euler/problem_551/sol1.py index bbdd4d6b039d..e7e9ea6347f5 100644 --- a/project_euler/problem_551/sol1.py +++ b/project_euler/problem_551/sol1.py @@ -13,7 +13,7 @@ """ ks = [k for k in range(2, 20 + 1)] -base = [10 ** k for k in range(ks[-1] + 1)] +base = [10**k for k in range(ks[-1] + 1)] memo = {} @@ -196,9 +196,9 @@ def solution(n): a_n = 0 for j in range(len(digits)): - a_n += digits[j] * 10 ** j + a_n += digits[j] * 10**j return a_n if __name__ == "__main__": - print(solution(10 ** 15)) + print(solution(10**15)) diff --git a/project_euler/problem_56/sol1.py b/project_euler/problem_56/sol1.py index 7a38f1f5a53d..c3186bf70764 100644 --- a/project_euler/problem_56/sol1.py +++ b/project_euler/problem_56/sol1.py @@ -18,7 +18,7 @@ def maximum_digital_sum(a: int, b: int) -> int: # RETURN the MAXIMUM from the list of SUMs of the list of INT converted from STR of BASE raised to the POWER return max( [ - sum([int(x) for x in str(base ** power)]) + sum([int(x) for x in str(base**power)]) for base in range(a) for power in range(b) ] diff --git a/searches/hill_climbing.py b/searches/hill_climbing.py index 324097ef5a24..cc9f8169b595 100644 --- a/searches/hill_climbing.py +++ b/searches/hill_climbing.py @@ -166,7 +166,7 @@ def hill_climbing( doctest.testmod() def test_f1(x, y): - return (x ** 2) + (y ** 2) + return (x**2) + (y**2) # starting the problem with initial coordinates (3, 4) prob = SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_f1) @@ -187,7 +187,7 @@ def test_f1(x, y): ) def test_f2(x, y): - return (3 * x ** 2) - (6 * y) + return (3 * x**2) - (6 * y) prob = SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_f1) local_min = hill_climbing(prob, find_max=True) diff --git a/searches/simulated_annealing.py b/searches/simulated_annealing.py index 969980357c1d..1ddde7c516df 100644 --- a/searches/simulated_annealing.py +++ b/searches/simulated_annealing.py @@ -94,7 +94,7 @@ def simulated_annealing( if __name__ == "__main__": def test_f1(x, y): - return (x ** 2) + (y ** 2) + return (x**2) + (y**2) # starting the problem with initial coordinates (12, 47) prob = SearchProblem(x=12, y=47, step_size=1, function_to_optimize=test_f1) @@ -117,7 +117,7 @@ def test_f1(x, y): ) def test_f2(x, y): - return (3 * x ** 2) - (6 * y) + return (3 * x**2) - (6 * y) prob = SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_f1) local_min = simulated_annealing(prob, find_max=False, visualization=True)