Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3fa014

Browse files
MaximSmolskiycclauss
andauthored
* updating DIRECTORY.md * Fix ruff * Fix * Fix * Fix * Revert "Fix" This reverts commit 5bc3bf3. * find_max.py: noqa: PLR1730 --------- Co-authored-by: MaximSmolskiy <MaximSmolskiy@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 2 deletions
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‎

Lines changed: 2 additions & 4 deletions
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‎

Lines changed: 1 addition & 2 deletions
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 2 deletions
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‎

Lines changed: 6 additions & 6 deletions
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‎

Lines changed: 1 addition & 2 deletions
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‎

Lines changed: 1 addition & 2 deletions
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‎

Lines changed: 1 addition & 2 deletions
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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /