Skip to content

Commit e3fa014

Browse files
* updating DIRECTORY.md * Fix ruff * Fix * Fix * Fix * Revert "Fix" This reverts commit 5bc3bf3. * find_max.py: noqa: PLR1730 --------- Co-authored-by: MaximSmolskiy <[email protected]> Co-authored-by: Christian Clauss <[email protected]>
1 parent 4841828 commit e3fa014

File tree

13 files changed

+22
-36
lines changed

13 files changed

+22
-36
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.5.7
19+
rev: v0.6.2
2020
hooks:
2121
- id: ruff
2222
- id: ruff-format

data_structures/binary_tree/number_of_possible_binary_trees.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ def binomial_coefficient(n: int, k: int) -> int:
3131
"""
3232
result = 1 # To kept the Calculated Value
3333
# Since C(n, k) = C(n, n-k)
34-
if k > (n - k):
35-
k = n - k
34+
k = min(k, n - k)
3635
# Calculate C(n,k)
3736
for i in range(k):
3837
result *= n - i

divide_and_conquer/closest_pair_of_points.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def dis_between_closest_pair(points, points_counts, min_dis=float("inf")):
5454
for i in range(points_counts - 1):
5555
for j in range(i + 1, points_counts):
5656
current_dis = euclidean_distance_sqr(points[i], points[j])
57-
if current_dis < min_dis:
58-
min_dis = current_dis
57+
min_dis = min(min_dis, current_dis)
5958
return min_dis
6059

6160

@@ -76,8 +75,7 @@ def dis_between_closest_in_strip(points, points_counts, min_dis=float("inf")):
7675
for i in range(min(6, points_counts - 1), points_counts):
7776
for j in range(max(0, i - 6), i):
7877
current_dis = euclidean_distance_sqr(points[i], points[j])
79-
if current_dis < min_dis:
80-
min_dis = current_dis
78+
min_dis = min(min_dis, current_dis)
8179
return min_dis
8280

8381

graphs/kahns_algorithm_long.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def longest_distance(graph):
1717
for x in graph[vertex]:
1818
indegree[x] -= 1
1919

20-
if long_dist[vertex] + 1 > long_dist[x]:
21-
long_dist[x] = long_dist[vertex] + 1
20+
long_dist[x] = max(long_dist[x], long_dist[vertex] + 1)
2221

2322
if indegree[x] == 0:
2423
queue.append(x)

maths/find_max.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def find_max_iterative(nums: list[int | float]) -> int | float:
2020
raise ValueError("find_max_iterative() arg is an empty sequence")
2121
max_num = nums[0]
2222
for x in nums:
23-
if x > max_num:
23+
if x > max_num: # noqa: PLR1730
2424
max_num = x
2525
return max_num
2626

maths/special_numbers/bell_numbers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def _binomial_coefficient(total_elements: int, elements_to_choose: int) -> int:
6161
if elements_to_choose in {0, total_elements}:
6262
return 1
6363

64-
if elements_to_choose > total_elements - elements_to_choose:
65-
elements_to_choose = total_elements - elements_to_choose
64+
elements_to_choose = min(elements_to_choose, total_elements - elements_to_choose)
6665

6766
coefficient = 1
6867
for i in range(elements_to_choose):

matrix/tests/test_matrix_operation.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
logger.addHandler(stream_handler)
3232

3333

34-
@pytest.mark.mat_ops()
34+
@pytest.mark.mat_ops
3535
@pytest.mark.parametrize(
3636
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]
3737
)
@@ -51,7 +51,7 @@ def test_addition(mat1, mat2):
5151
matop.add(mat1, mat2)
5252

5353

54-
@pytest.mark.mat_ops()
54+
@pytest.mark.mat_ops
5555
@pytest.mark.parametrize(
5656
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]
5757
)
@@ -71,7 +71,7 @@ def test_subtraction(mat1, mat2):
7171
assert matop.subtract(mat1, mat2)
7272

7373

74-
@pytest.mark.mat_ops()
74+
@pytest.mark.mat_ops
7575
@pytest.mark.parametrize(
7676
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]
7777
)
@@ -93,21 +93,21 @@ def test_multiplication(mat1, mat2):
9393
assert matop.subtract(mat1, mat2)
9494

9595

96-
@pytest.mark.mat_ops()
96+
@pytest.mark.mat_ops
9797
def test_scalar_multiply():
9898
act = (3.5 * np.array(mat_a)).tolist()
9999
theo = matop.scalar_multiply(mat_a, 3.5)
100100
assert theo == act
101101

102102

103-
@pytest.mark.mat_ops()
103+
@pytest.mark.mat_ops
104104
def test_identity():
105105
act = (np.identity(5)).tolist()
106106
theo = matop.identity(5)
107107
assert theo == act
108108

109109

110-
@pytest.mark.mat_ops()
110+
@pytest.mark.mat_ops
111111
@pytest.mark.parametrize("mat", [mat_a, mat_b, mat_c, mat_d, mat_e, mat_f])
112112
def test_transpose(mat):
113113
if (np.array(mat)).shape < (2, 2):

project_euler/problem_008/sol1.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def solution(n: str = N) -> int:
7575
product = 1
7676
for j in range(13):
7777
product *= int(n[i + j])
78-
if product > largest_product:
79-
largest_product = product
78+
largest_product = max(largest_product, product)
8079
return largest_product
8180

8281

project_euler/problem_009/sol2.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def solution(n: int = 1000) -> int:
3939
c = n - a - b
4040
if c * c == (a * a + b * b):
4141
candidate = a * b * c
42-
if candidate >= product:
43-
product = candidate
42+
product = max(product, candidate)
4443
return product
4544

4645

project_euler/problem_011/sol1.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def largest_product(grid):
6363
max_product = max(
6464
vert_product, horz_product, lr_diag_product, rl_diag_product
6565
)
66-
if max_product > largest:
67-
largest = max_product
66+
largest = max(largest, max_product)
6867

6968
return largest
7069

project_euler/problem_011/sol2.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ def solution():
4545
for i in range(20):
4646
for j in range(17):
4747
temp = grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3]
48-
if temp > maximum:
49-
maximum = temp
48+
maximum = max(maximum, temp)
5049

5150
# down
5251
for i in range(17):
5352
for j in range(20):
5453
temp = grid[i][j] * grid[i + 1][j] * grid[i + 2][j] * grid[i + 3][j]
55-
if temp > maximum:
56-
maximum = temp
54+
maximum = max(maximum, temp)
5755

5856
# diagonal 1
5957
for i in range(17):
@@ -64,8 +62,7 @@ def solution():
6462
* grid[i + 2][j + 2]
6563
* grid[i + 3][j + 3]
6664
)
67-
if temp > maximum:
68-
maximum = temp
65+
maximum = max(maximum, temp)
6966

7067
# diagonal 2
7168
for i in range(17):
@@ -76,8 +73,7 @@ def solution():
7673
* grid[i + 2][j - 2]
7774
* grid[i + 3][j - 3]
7875
)
79-
if temp > maximum:
80-
maximum = temp
76+
maximum = max(maximum, temp)
8177
return maximum
8278

8379

scheduling/highest_response_ratio_next.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def calculate_turn_around_time(
4646
i = 0
4747
while finished_process[i] == 1:
4848
i += 1
49-
if current_time < arrival_time[i]:
50-
current_time = arrival_time[i]
49+
current_time = max(current_time, arrival_time[i])
5150

5251
response_ratio = 0
5352
# Index showing the location of the process being performed

scheduling/shortest_job_first.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def calculate_waitingtime(
6666
finar = finish_time - arrival_time[short]
6767
waiting_time[short] = finar - burst_time[short]
6868

69-
if waiting_time[short] < 0:
70-
waiting_time[short] = 0
69+
waiting_time[short] = max(waiting_time[short], 0)
7170

7271
# Increment time
7372
increment_time += 1

0 commit comments

Comments
 (0)