diff --git a/Python/p001.py b/Python/p001.py index a90283d..05605da 100644 --- a/Python/p001.py +++ b/Python/p001.py @@ -9,16 +9,16 @@ from projecteuler import timing @timing def p001() -> None: - sum_ = 0 + _sum = 0 # Simple brute-force approach: try every number between 3 and 999, # check if it's a multiple of 3 or 5, if yes add it to the total. for i in range(3, 1000): if i % 3 == 0 or i % 5 == 0: - sum_ += i + _sum += i print('Project Euler, Problem 1') - print(f'Answer: {sum_}') + print(f'Answer: {_sum}') if __name__ == '__main__': diff --git a/Python/p002.py b/Python/p002.py index acc0ac4..23e01eb 100644 --- a/Python/p002.py +++ b/Python/p002.py @@ -16,20 +16,20 @@ def p002() -> None: fib1 = 1 fib2 = 2 fibn = fib1 + fib2 - sum_ = 2 + _sum = 2 # Simple brute-force approach: generate every value in the Fibonacci # sequence smaller than 4 million and if it's even add it to the total. while fibn < N: if fibn % 2 == 0: - sum_ = sum_ + fibn + _sum = _sum + fibn fib1 = fib2 fib2 = fibn fibn = fib1 + fib2 print('Project Euler, Problem 2') - print(f'Answer: {sum_}') + print(f'Answer: {_sum}') if __name__ == '__main__': diff --git a/Python/p004.py b/Python/p004.py index b6780e5..a3821dd 100644 --- a/Python/p004.py +++ b/Python/p004.py @@ -9,7 +9,7 @@ from projecteuler import is_palindrome, timing @timing def p004() -> None: - max_ = 0 + _max = 0 # Using a brute-force approach: generate every product of 3-digit numbers # and check if it's palindrome. If the product found is greater than the @@ -18,11 +18,11 @@ def p004() -> None: for j in range(i, 99, -1): num = i * j # Use the function defined in projecteuler.py to check if a number is palindrome. - if num > max_ and is_palindrome(num, 10): - max_ = num + if num > _max and is_palindrome(num, 10): + _max = num print('Project Euler, Problem 4') - print(f'Answer: {max_}') + print(f'Answer: {_max}') if __name__ == '__main__': diff --git a/Python/p010.py b/Python/p010.py index 4054538..6590ca3 100644 --- a/Python/p010.py +++ b/Python/p010.py @@ -14,15 +14,15 @@ def p010() -> None: # Use the function in projecteuler.py implementing the # Sieve of Eratosthenes algorithm to generate primes. primes = sieve(N) - sum_ = 0 + _sum = 0 # Sum all the primes for i in range(N): if primes[i] == 1: - sum_ = sum_ + i + _sum = _sum + i print('Project Euler, Problem 10') - print(f'Answer: {sum_}') + print(f'Answer: {_sum}') if __name__ == '__main__': diff --git a/Python/p011.py b/Python/p011.py index 6b039ad..e9246d6 100644 --- a/Python/p011.py +++ b/Python/p011.py @@ -53,7 +53,7 @@ def p011() -> None: [20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54], [1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]] - max_ = 0 + _max = 0 # Brute-force approach: for each number in the grid, try products with its three # adjacent numbers in every direction (horizontal, vertical and the two diagonals). @@ -67,7 +67,7 @@ def p011() -> None: prod = prod * grid[i][k] k = k + 1 - max_ = max(max_, prod) + _max = max(_max, prod) # Vertical direction. prod = 1 @@ -76,7 +76,7 @@ def p011() -> None: prod = prod * grid[k][j] k = k + 1 - max_ = max(max_, prod) + _max = max(_max, prod) # Diagonal direction, from top left to bottom right. prod = 1 @@ -88,7 +88,7 @@ def p011() -> None: k = k + 1 w = w + 1 - max_ = max(max_, prod) + _max = max(_max, prod) # The last diagonal is handled separately for i in range(17): @@ -103,10 +103,10 @@ def p011() -> None: k = k + 1 w = w - 1 - max_ = max(max_, prod) + _max = max(_max, prod) print('Project Euler, Problem 11') - print(f'Answer: {max_}') + print(f'Answer: {_max}') if __name__ == '__main__': diff --git a/Python/p013.py b/Python/p013.py index be96dcb..cf5df74 100644 --- a/Python/p013.py +++ b/Python/p013.py @@ -214,10 +214,10 @@ def p013() -> None: # Convert the list of numbers in a numpy array and calculate the sum numbers = np.array(numbers) - sum_ = str(numbers.sum()) + _sum = str(numbers.sum()) print('Project Euler, Problem 13') - print(f'Answer: {sum_[:10]}') + print(f'Answer: {_sum[:10]}') if __name__ == '__main__': diff --git a/Python/p014.py b/Python/p014.py index 777ad8d..20bedf1 100644 --- a/Python/p014.py +++ b/Python/p014.py @@ -47,7 +47,7 @@ def collatz_length(n: int) -> int: @timing def p014() -> None: max_l = 0 - max_ = 0 + _max = 0 # For each number from 1 to 1000000, find the length of the sequence # and save its value, so that it can be used for the next numbers. @@ -57,10 +57,10 @@ def p014() -> None: if count > max_l: max_l = count - max_ = i + _max = i print('Project Euler, Problem 14') - print(f'Answer: {max_}') + print(f'Answer: {_max}') if __name__ == '__main__': diff --git a/Python/p016.py b/Python/p016.py index 1621899..3acda86 100644 --- a/Python/p016.py +++ b/Python/p016.py @@ -13,13 +13,13 @@ def p016() -> None: # the sum of the digits res = str(2 ** 1000) - sum_ = 0 + _sum = 0 for i in res: - sum_ = sum_ + int(i) + _sum = _sum + int(i) print('Project Euler, Problem 16') - print(f'Answer: {sum_}') + print(f'Answer: {_sum}') if __name__ == '__main__': diff --git a/Python/p017.py b/Python/p017.py index bdb161c..c56ad4c 100644 --- a/Python/p017.py +++ b/Python/p017.py @@ -21,11 +21,11 @@ def p017() -> None: [13, 13, 15, 14, 14, 13, 15, 15, 14], [11]] - sum_ = 0 + _sum = 0 # Sum the letters of the first 19 numbers. for i in range(19): - sum_ = sum_ + n_letters[0][i] + _sum = _sum + n_letters[0][i] # Add the letters of the numbers from 20 to 99. for i in range(8): @@ -37,7 +37,7 @@ def p017() -> None: for j in range(9): n_letters[1][i] = n_letters[1][i] + n_letters[0][j] - sum_ = sum_ + n_letters[1][i] + _sum = _sum + n_letters[1][i] # Add the letters of the numbers from 100 to 999. for i in range(9): @@ -52,13 +52,13 @@ def p017() -> None: n_letters[2][i] = n_letters[2][i] + n_letters[1][j] # "One hundred", "two hundred", ... don't have the "and", so remove # three letters for each of them. - sum_ = sum_ + n_letters[2][i] - 3 + _sum = _sum + n_letters[2][i] - 3 # Add "one thousand". - sum_ = sum_ + n_letters[3][0] + _sum = _sum + n_letters[3][0] print('Project Euler, Problem 17') - print(f'Answer: {sum_}') + print(f'Answer: {_sum}') if __name__ == '__main__': diff --git a/Python/p018.py b/Python/p018.py index c46de53..af344c5 100644 --- a/Python/p018.py +++ b/Python/p018.py @@ -53,10 +53,10 @@ def p018() -> None: triang[i] = list(map(int, triang[i])) # Use the function implemented in projecteuler.c to find the maximum path. - max_ = find_max_path(triang, 15) + _max = find_max_path(triang, 15) print('Project Euler, Problem 18') - print(f'Answer: {max_}') + print(f'Answer: {_max}') if __name__ == '__main__': diff --git a/Python/p020.py b/Python/p020.py index cace681..a9d84be 100644 --- a/Python/p020.py +++ b/Python/p020.py @@ -17,13 +17,13 @@ def p020() -> None: # Calculate the factorial, convert the result to string and sum the digits. n = str(factorial(100)) - sum_ = 0 + _sum = 0 for i in n: - sum_ = sum_ + int(i) + _sum = _sum + int(i) print('Project Euler, Problem 20') - print(f'Answer: {sum_}') + print(f'Answer: {_sum}') if __name__ == '__main__': diff --git a/Python/projecteuler.py b/Python/projecteuler.py index 76697e5..9541fd7 100644 --- a/Python/projecteuler.py +++ b/Python/projecteuler.py @@ -500,12 +500,12 @@ def dijkstra(matrix: List[List[int]], distances: List[List[int]], m: int, n: int if j > 0 and distances[i][j] + matrix[i][j-1] < distances[i][j-1]: distances[i][j-1] = distances[i][j] + matrix[i][j-1] - min_ = 999999999 + _min = 999999999 for i in range(m): for j in range(n): - if not visited[i][j] and distances[i][j] <= min_: - min_ = distances[i][j] + if not visited[i][j] and distances[i][j] <= _min: + _min = distances[i][j] min_i = i min_j = j