mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 13:01:08 +00:00
Fix ruff (#11527)
* updating DIRECTORY.md
* Fix ruff
* Fix
* Fix
* Fix
* Revert "Fix"
This reverts commit 5bc3bf3422
.
* find_max.py: noqa: PLR1730
---------
Co-authored-by: MaximSmolskiy <MaximSmolskiy@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
48418280b1
commit
e3fa014a5a
|
@ -16,7 +16,7 @@ repos:
|
|||
- id: auto-walrus
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.5.7
|
||||
rev: v0.6.2
|
||||
hooks:
|
||||
- id: ruff
|
||||
- id: ruff-format
|
||||
|
|
|
@ -31,8 +31,7 @@ def binomial_coefficient(n: int, k: int) -> int:
|
|||
"""
|
||||
result = 1 # To kept the Calculated Value
|
||||
# Since C(n, k) = C(n, n-k)
|
||||
if k > (n - k):
|
||||
k = n - k
|
||||
k = min(k, n - k)
|
||||
# Calculate C(n,k)
|
||||
for i in range(k):
|
||||
result *= n - i
|
||||
|
|
|
@ -54,8 +54,7 @@ def dis_between_closest_pair(points, points_counts, min_dis=float("inf")):
|
|||
for i in range(points_counts - 1):
|
||||
for j in range(i + 1, points_counts):
|
||||
current_dis = euclidean_distance_sqr(points[i], points[j])
|
||||
if current_dis < min_dis:
|
||||
min_dis = current_dis
|
||||
min_dis = min(min_dis, current_dis)
|
||||
return min_dis
|
||||
|
||||
|
||||
|
@ -76,8 +75,7 @@ def dis_between_closest_in_strip(points, points_counts, min_dis=float("inf")):
|
|||
for i in range(min(6, points_counts - 1), points_counts):
|
||||
for j in range(max(0, i - 6), i):
|
||||
current_dis = euclidean_distance_sqr(points[i], points[j])
|
||||
if current_dis < min_dis:
|
||||
min_dis = current_dis
|
||||
min_dis = min(min_dis, current_dis)
|
||||
return min_dis
|
||||
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@ def longest_distance(graph):
|
|||
for x in graph[vertex]:
|
||||
indegree[x] -= 1
|
||||
|
||||
if long_dist[vertex] + 1 > long_dist[x]:
|
||||
long_dist[x] = long_dist[vertex] + 1
|
||||
long_dist[x] = max(long_dist[x], long_dist[vertex] + 1)
|
||||
|
||||
if indegree[x] == 0:
|
||||
queue.append(x)
|
||||
|
|
|
@ -20,7 +20,7 @@ def find_max_iterative(nums: list[int | float]) -> int | float:
|
|||
raise ValueError("find_max_iterative() arg is an empty sequence")
|
||||
max_num = nums[0]
|
||||
for x in nums:
|
||||
if x > max_num:
|
||||
if x > max_num: # noqa: PLR1730
|
||||
max_num = x
|
||||
return max_num
|
||||
|
||||
|
|
|
@ -61,8 +61,7 @@ def _binomial_coefficient(total_elements: int, elements_to_choose: int) -> int:
|
|||
if elements_to_choose in {0, total_elements}:
|
||||
return 1
|
||||
|
||||
if elements_to_choose > total_elements - elements_to_choose:
|
||||
elements_to_choose = total_elements - elements_to_choose
|
||||
elements_to_choose = min(elements_to_choose, total_elements - elements_to_choose)
|
||||
|
||||
coefficient = 1
|
||||
for i in range(elements_to_choose):
|
||||
|
|
|
@ -31,7 +31,7 @@ stream_handler = logging.StreamHandler(sys.stdout)
|
|||
logger.addHandler(stream_handler)
|
||||
|
||||
|
||||
@pytest.mark.mat_ops()
|
||||
@pytest.mark.mat_ops
|
||||
@pytest.mark.parametrize(
|
||||
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]
|
||||
)
|
||||
|
@ -51,7 +51,7 @@ def test_addition(mat1, mat2):
|
|||
matop.add(mat1, mat2)
|
||||
|
||||
|
||||
@pytest.mark.mat_ops()
|
||||
@pytest.mark.mat_ops
|
||||
@pytest.mark.parametrize(
|
||||
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]
|
||||
)
|
||||
|
@ -71,7 +71,7 @@ def test_subtraction(mat1, mat2):
|
|||
assert matop.subtract(mat1, mat2)
|
||||
|
||||
|
||||
@pytest.mark.mat_ops()
|
||||
@pytest.mark.mat_ops
|
||||
@pytest.mark.parametrize(
|
||||
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]
|
||||
)
|
||||
|
@ -93,21 +93,21 @@ def test_multiplication(mat1, mat2):
|
|||
assert matop.subtract(mat1, mat2)
|
||||
|
||||
|
||||
@pytest.mark.mat_ops()
|
||||
@pytest.mark.mat_ops
|
||||
def test_scalar_multiply():
|
||||
act = (3.5 * np.array(mat_a)).tolist()
|
||||
theo = matop.scalar_multiply(mat_a, 3.5)
|
||||
assert theo == act
|
||||
|
||||
|
||||
@pytest.mark.mat_ops()
|
||||
@pytest.mark.mat_ops
|
||||
def test_identity():
|
||||
act = (np.identity(5)).tolist()
|
||||
theo = matop.identity(5)
|
||||
assert theo == act
|
||||
|
||||
|
||||
@pytest.mark.mat_ops()
|
||||
@pytest.mark.mat_ops
|
||||
@pytest.mark.parametrize("mat", [mat_a, mat_b, mat_c, mat_d, mat_e, mat_f])
|
||||
def test_transpose(mat):
|
||||
if (np.array(mat)).shape < (2, 2):
|
||||
|
|
|
@ -75,8 +75,7 @@ def solution(n: str = N) -> int:
|
|||
product = 1
|
||||
for j in range(13):
|
||||
product *= int(n[i + j])
|
||||
if product > largest_product:
|
||||
largest_product = product
|
||||
largest_product = max(largest_product, product)
|
||||
return largest_product
|
||||
|
||||
|
||||
|
|
|
@ -39,8 +39,7 @@ def solution(n: int = 1000) -> int:
|
|||
c = n - a - b
|
||||
if c * c == (a * a + b * b):
|
||||
candidate = a * b * c
|
||||
if candidate >= product:
|
||||
product = candidate
|
||||
product = max(product, candidate)
|
||||
return product
|
||||
|
||||
|
||||
|
|
|
@ -63,8 +63,7 @@ def largest_product(grid):
|
|||
max_product = max(
|
||||
vert_product, horz_product, lr_diag_product, rl_diag_product
|
||||
)
|
||||
if max_product > largest:
|
||||
largest = max_product
|
||||
largest = max(largest, max_product)
|
||||
|
||||
return largest
|
||||
|
||||
|
|
|
@ -45,15 +45,13 @@ def solution():
|
|||
for i in range(20):
|
||||
for j in range(17):
|
||||
temp = grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3]
|
||||
if temp > maximum:
|
||||
maximum = temp
|
||||
maximum = max(maximum, temp)
|
||||
|
||||
# down
|
||||
for i in range(17):
|
||||
for j in range(20):
|
||||
temp = grid[i][j] * grid[i + 1][j] * grid[i + 2][j] * grid[i + 3][j]
|
||||
if temp > maximum:
|
||||
maximum = temp
|
||||
maximum = max(maximum, temp)
|
||||
|
||||
# diagonal 1
|
||||
for i in range(17):
|
||||
|
@ -64,8 +62,7 @@ def solution():
|
|||
* grid[i + 2][j + 2]
|
||||
* grid[i + 3][j + 3]
|
||||
)
|
||||
if temp > maximum:
|
||||
maximum = temp
|
||||
maximum = max(maximum, temp)
|
||||
|
||||
# diagonal 2
|
||||
for i in range(17):
|
||||
|
@ -76,8 +73,7 @@ def solution():
|
|||
* grid[i + 2][j - 2]
|
||||
* grid[i + 3][j - 3]
|
||||
)
|
||||
if temp > maximum:
|
||||
maximum = temp
|
||||
maximum = max(maximum, temp)
|
||||
return maximum
|
||||
|
||||
|
||||
|
|
|
@ -46,8 +46,7 @@ def calculate_turn_around_time(
|
|||
i = 0
|
||||
while finished_process[i] == 1:
|
||||
i += 1
|
||||
if current_time < arrival_time[i]:
|
||||
current_time = arrival_time[i]
|
||||
current_time = max(current_time, arrival_time[i])
|
||||
|
||||
response_ratio = 0
|
||||
# Index showing the location of the process being performed
|
||||
|
|
|
@ -66,8 +66,7 @@ def calculate_waitingtime(
|
|||
finar = finish_time - arrival_time[short]
|
||||
waiting_time[short] = finar - burst_time[short]
|
||||
|
||||
if waiting_time[short] < 0:
|
||||
waiting_time[short] = 0
|
||||
waiting_time[short] = max(waiting_time[short], 0)
|
||||
|
||||
# Increment time
|
||||
increment_time += 1
|
||||
|
|
Loading…
Reference in New Issue
Block a user