Skip to content

Commit 24d3cf8

Browse files
cclaussgithub-actions
and
github-actions
authored
The black formatter is no longer beta (TheAlgorithms#5960)
* The black formatter is no longer beta * pre-commit autoupdate * pre-commit autoupdate * Remove project_euler/problem_145 which is killing our CI tests * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent c15a4d5 commit 24d3cf8

File tree

81 files changed

+139
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+139
-228
lines changed

.pre-commit-config.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.4.0
3+
rev: v4.1.0
44
hooks:
55
- id: check-executables-have-shebangs
66
- id: check-yaml
@@ -14,26 +14,26 @@ repos:
1414
- id: requirements-txt-fixer
1515

1616
- repo: https://github.com/psf/black
17-
rev: 21.4b0
17+
rev: 22.1.0
1818
hooks:
1919
- id: black
2020

2121
- repo: https://github.com/PyCQA/isort
22-
rev: 5.8.0
22+
rev: 5.10.1
2323
hooks:
2424
- id: isort
2525
args:
2626
- --profile=black
2727

2828
- repo: https://github.com/asottile/pyupgrade
29-
rev: v2.29.0
29+
rev: v2.31.0
3030
hooks:
3131
- id: pyupgrade
3232
args:
3333
- --py39-plus
3434

3535
- repo: https://gitlab.com/pycqa/flake8
36-
rev: 3.9.1
36+
rev: 3.9.2
3737
hooks:
3838
- id: flake8
3939
args:
@@ -42,7 +42,7 @@ repos:
4242
- --max-line-length=88
4343

4444
- repo: https://github.com/pre-commit/mirrors-mypy
45-
rev: v0.910
45+
rev: v0.931
4646
hooks:
4747
- id: mypy
4848
args:
@@ -51,11 +51,11 @@ repos:
5151
- --non-interactive
5252

5353
- repo: https://github.com/codespell-project/codespell
54-
rev: v2.0.0
54+
rev: v2.1.0
5555
hooks:
5656
- id: codespell
5757
args:
58-
- --ignore-words-list=ans,crate,fo,followings,hist,iff,mater,secant,som,tim
58+
- --ignore-words-list=ans,crate,fo,followings,hist,iff,mater,secant,som,sur,tim
5959
- --skip="./.*,./strings/dictionary.txt,./strings/words.txt,./project_euler/problem_022/p022_names.txt"
6060
exclude: |
6161
(?x)^(

DIRECTORY.md

-2
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,6 @@
856856
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_135/sol1.py)
857857
* Problem 144
858858
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_144/sol1.py)
859-
* Problem 145
860-
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_145/sol1.py)
861859
* Problem 173
862860
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_173/sol1.py)
863861
* Problem 174

arithmetic_analysis/bisection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float:
3232
raise ValueError("could not find root in given interval.")
3333
else:
3434
mid: float = start + (end - start) / 2.0
35-
while abs(start - mid) > 10 ** -7: # until precisely equals to 10^-7
35+
while abs(start - mid) > 10**-7: # until precisely equals to 10^-7
3636
if function(mid) == 0:
3737
return mid
3838
elif function(mid) * function(start) < 0:
@@ -44,7 +44,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float:
4444

4545

4646
def f(x: float) -> float:
47-
return x ** 3 - 2 * x - 5
47+
return x**3 - 2 * x - 5
4848

4949

5050
if __name__ == "__main__":

arithmetic_analysis/in_static_equilibrium.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def polar_force(
2323

2424

2525
def in_static_equilibrium(
26-
forces: ndarray, location: ndarray, eps: float = 10 ** -1
26+
forces: ndarray, location: ndarray, eps: float = 10**-1
2727
) -> bool:
2828
"""
2929
Check if a system is in equilibrium.

arithmetic_analysis/intersection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def intersection(function: Callable[[float], float], x0: float, x1: float) -> fl
3535
x_n2: float = x_n1 - (
3636
function(x_n1) / ((function(x_n1) - function(x_n)) / (x_n1 - x_n))
3737
)
38-
if abs(x_n2 - x_n1) < 10 ** -5:
38+
if abs(x_n2 - x_n1) < 10**-5:
3939
return x_n2
4040
x_n = x_n1
4141
x_n1 = x_n2

arithmetic_analysis/newton_method.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ def newton(
3737
next_guess = prev_guess - function(prev_guess) / derivative(prev_guess)
3838
except ZeroDivisionError:
3939
raise ZeroDivisionError("Could not find root") from None
40-
if abs(prev_guess - next_guess) < 10 ** -5:
40+
if abs(prev_guess - next_guess) < 10**-5:
4141
return next_guess
4242
prev_guess = next_guess
4343

4444

4545
def f(x: float) -> float:
46-
return (x ** 3) - (2 * x) - 5
46+
return (x**3) - (2 * x) - 5
4747

4848

4949
def f1(x: float) -> float:
50-
return 3 * (x ** 2) - 2
50+
return 3 * (x**2) - 2
5151

5252

5353
if __name__ == "__main__":

arithmetic_analysis/newton_raphson.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def newton_raphson(
14-
func: str, a: float | Decimal, precision: float = 10 ** -10
14+
func: str, a: float | Decimal, precision: float = 10**-10
1515
) -> float:
1616
"""Finds root from the point 'a' onwards by Newton-Raphson method
1717
>>> newton_raphson("sin(x)", 2)

ciphers/deterministic_miller_rabin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def miller_rabin(n: int, allow_probable: bool = False) -> bool:
7373
for prime in plist:
7474
pr = False
7575
for r in range(s):
76-
m = pow(prime, d * 2 ** r, n)
76+
m = pow(prime, d * 2**r, n)
7777
# see article for analysis explanation for m
7878
if (r == 0 and m == 1) or ((m + 1) % n == 0):
7979
pr = True

ciphers/rabin_miller.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def rabinMiller(num: int) -> bool:
2121
return False
2222
else:
2323
i = i + 1
24-
v = (v ** 2) % num
24+
v = (v**2) % num
2525
return True
2626

2727

ciphers/rsa_cipher.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def get_text_from_blocks(
2929
block_message: list[str] = []
3030
for i in range(block_size - 1, -1, -1):
3131
if len(message) + i < message_length:
32-
ascii_number = block_int // (BYTE_SIZE ** i)
33-
block_int = block_int % (BYTE_SIZE ** i)
32+
ascii_number = block_int // (BYTE_SIZE**i)
33+
block_int = block_int % (BYTE_SIZE**i)
3434
block_message.insert(0, chr(ascii_number))
3535
message.extend(block_message)
3636
return "".join(message)

ciphers/rsa_factorization.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def rsafactor(d: int, e: int, N: int) -> list[int]:
4040
while True:
4141
if t % 2 == 0:
4242
t = t // 2
43-
x = (g ** t) % N
43+
x = (g**t) % N
4444
y = math.gcd(x - 1, N)
4545
if x > 1 and y > 1:
4646
p = y

computer_vision/harris_corner.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def detect(self, img_path: str) -> tuple[cv2.Mat, list[list[int]]]:
3939
color_img = img.copy()
4040
color_img = cv2.cvtColor(color_img, cv2.COLOR_GRAY2RGB)
4141
dy, dx = np.gradient(img)
42-
ixx = dx ** 2
43-
iyy = dy ** 2
42+
ixx = dx**2
43+
iyy = dy**2
4444
ixy = dx * dy
4545
k = 0.04
4646
offset = self.window_size // 2
@@ -56,9 +56,9 @@ def detect(self, img_path: str) -> tuple[cv2.Mat, list[list[int]]]:
5656
y - offset : y + offset + 1, x - offset : x + offset + 1
5757
].sum()
5858

59-
det = (wxx * wyy) - (wxy ** 2)
59+
det = (wxx * wyy) - (wxy**2)
6060
trace = wxx + wyy
61-
r = det - k * (trace ** 2)
61+
r = det - k * (trace**2)
6262
# Can change the value
6363
if r > 0.5:
6464
corner_list.append([x, y, r])

digital_image_processing/filters/gabor_filter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def gabor_filter_kernel(
4949

5050
# fill kernel
5151
gabor[y, x] = np.exp(
52-
-(_x ** 2 + gamma ** 2 * _y ** 2) / (2 * sigma ** 2)
52+
-(_x**2 + gamma**2 * _y**2) / (2 * sigma**2)
5353
) * np.cos(2 * np.pi * _x / lambd + psi)
5454

5555
return gabor

digital_image_processing/index_calculation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def CVI(self):
203203
https://www.indexdatabase.de/db/i-single.php?id=391
204204
:return: index
205205
"""
206-
return self.nir * (self.red / (self.green ** 2))
206+
return self.nir * (self.red / (self.green**2))
207207

208208
def GLI(self):
209209
"""
@@ -295,7 +295,7 @@ def ATSAVI(self, X=0.08, a=1.22, b=0.03):
295295
"""
296296
return a * (
297297
(self.nir - a * self.red - b)
298-
/ (a * self.nir + self.red - a * b + X * (1 + a ** 2))
298+
/ (a * self.nir + self.red - a * b + X * (1 + a**2))
299299
)
300300

301301
def BWDRVI(self):
@@ -363,7 +363,7 @@ def GEMI(self):
363363
https://www.indexdatabase.de/db/i-single.php?id=25
364364
:return: index
365365
"""
366-
n = (2 * (self.nir ** 2 - self.red ** 2) + 1.5 * self.nir + 0.5 * self.red) / (
366+
n = (2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
367367
self.nir + self.red + 0.5
368368
)
369369
return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red)

electronics/carrier_concentration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def carrier_concentration(
5353
elif electron_conc == 0:
5454
return (
5555
"electron_conc",
56-
intrinsic_conc ** 2 / hole_conc,
56+
intrinsic_conc**2 / hole_conc,
5757
)
5858
elif hole_conc == 0:
5959
return (
6060
"hole_conc",
61-
intrinsic_conc ** 2 / electron_conc,
61+
intrinsic_conc**2 / electron_conc,
6262
)
6363
elif intrinsic_conc == 0:
6464
return (

electronics/coulombs_law.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ def couloumbs_law(
6666
if distance < 0:
6767
raise ValueError("Distance cannot be negative")
6868
if force == 0:
69-
force = COULOMBS_CONSTANT * charge_product / (distance ** 2)
69+
force = COULOMBS_CONSTANT * charge_product / (distance**2)
7070
return {"force": force}
7171
elif charge1 == 0:
72-
charge1 = abs(force) * (distance ** 2) / (COULOMBS_CONSTANT * charge2)
72+
charge1 = abs(force) * (distance**2) / (COULOMBS_CONSTANT * charge2)
7373
return {"charge1": charge1}
7474
elif charge2 == 0:
75-
charge2 = abs(force) * (distance ** 2) / (COULOMBS_CONSTANT * charge1)
75+
charge2 = abs(force) * (distance**2) / (COULOMBS_CONSTANT * charge1)
7676
return {"charge2": charge2}
7777
elif distance == 0:
7878
distance = (COULOMBS_CONSTANT * charge_product / abs(force)) ** 0.5

graphics/bezier_curve.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def basis_function(self, t: float) -> list[float]:
4040
for i in range(len(self.list_of_points)):
4141
# basis function for each i
4242
output_values.append(
43-
comb(self.degree, i) * ((1 - t) ** (self.degree - i)) * (t ** i)
43+
comb(self.degree, i) * ((1 - t) ** (self.degree - i)) * (t**i)
4444
)
4545
# the basis must sum up to 1 for it to produce a valid Bezier curve.
4646
assert round(sum(output_values), 5) == 1

graphs/bidirectional_a_star.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def calculate_heuristic(self) -> float:
6868
if HEURISTIC == 1:
6969
return abs(dx) + abs(dy)
7070
else:
71-
return sqrt(dy ** 2 + dx ** 2)
71+
return sqrt(dy**2 + dx**2)
7272

7373
def __lt__(self, other: Node) -> bool:
7474
return self.f_cost < other.f_cost

hashes/chaos_machine.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def xorshift(X, Y):
6363
params_space[key] = (machine_time * 0.01 + r * 1.01) % 1 + 3
6464

6565
# Choosing Chaotic Data
66-
X = int(buffer_space[(key + 2) % m] * (10 ** 10))
67-
Y = int(buffer_space[(key - 2) % m] * (10 ** 10))
66+
X = int(buffer_space[(key + 2) % m] * (10**10))
67+
Y = int(buffer_space[(key - 2) % m] * (10**10))
6868

6969
# Machine Time
7070
machine_time += 1

hashes/hamming_code.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def emitterConverter(sizePar, data):
7878
>>> emitterConverter(4, "101010111111")
7979
['1', '1', '1', '1', '0', '1', '0', '0', '1', '0', '1', '1', '1', '1', '1', '1']
8080
"""
81-
if sizePar + len(data) <= 2 ** sizePar - (len(data) - 1):
81+
if sizePar + len(data) <= 2**sizePar - (len(data) - 1):
8282
print("ERROR - size of parity don't match with size of data")
8383
exit(0)
8484

hashes/md5.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def not32(i):
9494

9595

9696
def sum32(a, b):
97-
return (a + b) % 2 ** 32
97+
return (a + b) % 2**32
9898

9999

100100
def leftrot32(i, s):
@@ -114,7 +114,7 @@ def md5me(testString):
114114
bs += format(ord(i), "08b")
115115
bs = pad(bs)
116116

117-
tvals = [int(2 ** 32 * abs(math.sin(i + 1))) for i in range(64)]
117+
tvals = [int(2**32 * abs(math.sin(i + 1))) for i in range(64)]
118118

119119
a0 = 0x67452301
120120
b0 = 0xEFCDAB89
@@ -211,7 +211,7 @@ def md5me(testString):
211211
dtemp = D
212212
D = C
213213
C = B
214-
B = sum32(B, leftrot32((A + f + tvals[i] + m[g]) % 2 ** 32, s[i]))
214+
B = sum32(B, leftrot32((A + f + tvals[i] + m[g]) % 2**32, s[i]))
215215
A = dtemp
216216
a0 = sum32(a0, A)
217217
b0 = sum32(b0, B)

linear_algebra/src/lib.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def euclidean_length(self) -> float:
172172
"""
173173
if len(self.__components) == 0:
174174
raise Exception("Vector is empty")
175-
squares = [c ** 2 for c in self.__components]
175+
squares = [c**2 for c in self.__components]
176176
return math.sqrt(sum(squares))
177177

178178
def angle(self, other: Vector, deg: bool = False) -> float:

machine_learning/k_means_clust.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def compute_heterogeneity(data, k, centroids, cluster_assignment):
112112
distances = pairwise_distances(
113113
member_data_points, [centroids[i]], metric="euclidean"
114114
)
115-
squared_distances = distances ** 2
115+
squared_distances = distances**2
116116
heterogeneity += np.sum(squared_distances)
117117

118118
return heterogeneity

machine_learning/local_weighted_learning/local_weighted_learning.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def weighted_matrix(point: np.mat, training_data_x: np.mat, bandwidth: float) ->
2525
# calculating weights for all training examples [x(i)'s]
2626
for j in range(m):
2727
diff = point - training_data_x[j]
28-
weights[j, j] = np.exp(diff * diff.T / (-2.0 * bandwidth ** 2))
28+
weights[j, j] = np.exp(diff * diff.T / (-2.0 * bandwidth**2))
2929
return weights
3030

3131

machine_learning/sequential_minimum_optimization.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,15 @@ def _get_new_alpha(self, i1, i2, a1, a2, e1, e2, y1, y2):
345345
ol = (
346346
l1 * f1
347347
+ L * f2
348-
+ 1 / 2 * l1 ** 2 * K(i1, i1)
349-
+ 1 / 2 * L ** 2 * K(i2, i2)
348+
+ 1 / 2 * l1**2 * K(i1, i1)
349+
+ 1 / 2 * L**2 * K(i2, i2)
350350
+ s * L * l1 * K(i1, i2)
351351
)
352352
oh = (
353353
h1 * f1
354354
+ H * f2
355-
+ 1 / 2 * h1 ** 2 * K(i1, i1)
356-
+ 1 / 2 * H ** 2 * K(i2, i2)
355+
+ 1 / 2 * h1**2 * K(i1, i1)
356+
+ 1 / 2 * H**2 * K(i2, i2)
357357
+ s * H * h1 * K(i1, i2)
358358
)
359359
"""

0 commit comments

Comments
 (0)