* 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:
Maxim Smolskiy 2024-08-25 18:33:11 +03:00 committed by GitHub
parent 48418280b1
commit e3fa014a5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 22 additions and 36 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus - id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7 rev: v0.6.2
hooks: hooks:
- id: ruff - id: ruff
- id: ruff-format - id: ruff-format

View File

@ -31,8 +31,7 @@ def binomial_coefficient(n: int, k: int) -> int:
""" """
result = 1 # To kept the Calculated Value result = 1 # To kept the Calculated Value
# Since C(n, k) = C(n, n-k) # Since C(n, k) = C(n, n-k)
if k > (n - k): k = min(k, n - k)
k = n - k
# Calculate C(n,k) # Calculate C(n,k)
for i in range(k): for i in range(k):
result *= n - i result *= n - i

View File

@ -54,8 +54,7 @@ def dis_between_closest_pair(points, points_counts, min_dis=float("inf")):
for i in range(points_counts - 1): for i in range(points_counts - 1):
for j in range(i + 1, points_counts): for j in range(i + 1, points_counts):
current_dis = euclidean_distance_sqr(points[i], points[j]) current_dis = euclidean_distance_sqr(points[i], points[j])
if current_dis < min_dis: min_dis = min(min_dis, current_dis)
min_dis = current_dis
return min_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 i in range(min(6, points_counts - 1), points_counts):
for j in range(max(0, i - 6), i): for j in range(max(0, i - 6), i):
current_dis = euclidean_distance_sqr(points[i], points[j]) current_dis = euclidean_distance_sqr(points[i], points[j])
if current_dis < min_dis: min_dis = min(min_dis, current_dis)
min_dis = current_dis
return min_dis return min_dis

View File

@ -17,8 +17,7 @@ def longest_distance(graph):
for x in graph[vertex]: for x in graph[vertex]:
indegree[x] -= 1 indegree[x] -= 1
if long_dist[vertex] + 1 > long_dist[x]: long_dist[x] = max(long_dist[x], long_dist[vertex] + 1)
long_dist[x] = long_dist[vertex] + 1
if indegree[x] == 0: if indegree[x] == 0:
queue.append(x) queue.append(x)

View File

@ -20,7 +20,7 @@ def find_max_iterative(nums: list[int | float]) -> int | float:
raise ValueError("find_max_iterative() arg is an empty sequence") raise ValueError("find_max_iterative() arg is an empty sequence")
max_num = nums[0] max_num = nums[0]
for x in nums: for x in nums:
if x > max_num: if x > max_num: # noqa: PLR1730
max_num = x max_num = x
return max_num return max_num

View File

@ -61,8 +61,7 @@ def _binomial_coefficient(total_elements: int, elements_to_choose: int) -> int:
if elements_to_choose in {0, total_elements}: if elements_to_choose in {0, total_elements}:
return 1 return 1
if elements_to_choose > total_elements - elements_to_choose: elements_to_choose = min(elements_to_choose, total_elements - elements_to_choose)
elements_to_choose = total_elements - elements_to_choose
coefficient = 1 coefficient = 1
for i in range(elements_to_choose): for i in range(elements_to_choose):

View File

@ -31,7 +31,7 @@ stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler) logger.addHandler(stream_handler)
@pytest.mark.mat_ops() @pytest.mark.mat_ops
@pytest.mark.parametrize( @pytest.mark.parametrize(
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)] ("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) matop.add(mat1, mat2)
@pytest.mark.mat_ops() @pytest.mark.mat_ops
@pytest.mark.parametrize( @pytest.mark.parametrize(
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)] ("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) assert matop.subtract(mat1, mat2)
@pytest.mark.mat_ops() @pytest.mark.mat_ops
@pytest.mark.parametrize( @pytest.mark.parametrize(
("mat1", "mat2"), [(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)] ("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) assert matop.subtract(mat1, mat2)
@pytest.mark.mat_ops() @pytest.mark.mat_ops
def test_scalar_multiply(): def test_scalar_multiply():
act = (3.5 * np.array(mat_a)).tolist() act = (3.5 * np.array(mat_a)).tolist()
theo = matop.scalar_multiply(mat_a, 3.5) theo = matop.scalar_multiply(mat_a, 3.5)
assert theo == act assert theo == act
@pytest.mark.mat_ops() @pytest.mark.mat_ops
def test_identity(): def test_identity():
act = (np.identity(5)).tolist() act = (np.identity(5)).tolist()
theo = matop.identity(5) theo = matop.identity(5)
assert theo == act 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]) @pytest.mark.parametrize("mat", [mat_a, mat_b, mat_c, mat_d, mat_e, mat_f])
def test_transpose(mat): def test_transpose(mat):
if (np.array(mat)).shape < (2, 2): if (np.array(mat)).shape < (2, 2):

View File

@ -75,8 +75,7 @@ def solution(n: str = N) -> int:
product = 1 product = 1
for j in range(13): for j in range(13):
product *= int(n[i + j]) product *= int(n[i + j])
if product > largest_product: largest_product = max(largest_product, product)
largest_product = product
return largest_product return largest_product

View File

@ -39,8 +39,7 @@ def solution(n: int = 1000) -> int:
c = n - a - b c = n - a - b
if c * c == (a * a + b * b): if c * c == (a * a + b * b):
candidate = a * b * c candidate = a * b * c
if candidate >= product: product = max(product, candidate)
product = candidate
return product return product

View File

@ -63,8 +63,7 @@ def largest_product(grid):
max_product = max( max_product = max(
vert_product, horz_product, lr_diag_product, rl_diag_product vert_product, horz_product, lr_diag_product, rl_diag_product
) )
if max_product > largest: largest = max(largest, max_product)
largest = max_product
return largest return largest

View File

@ -45,15 +45,13 @@ def solution():
for i in range(20): for i in range(20):
for j in range(17): for j in range(17):
temp = grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3] temp = grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3]
if temp > maximum: maximum = max(maximum, temp)
maximum = temp
# down # down
for i in range(17): for i in range(17):
for j in range(20): for j in range(20):
temp = grid[i][j] * grid[i + 1][j] * grid[i + 2][j] * grid[i + 3][j] temp = grid[i][j] * grid[i + 1][j] * grid[i + 2][j] * grid[i + 3][j]
if temp > maximum: maximum = max(maximum, temp)
maximum = temp
# diagonal 1 # diagonal 1
for i in range(17): for i in range(17):
@ -64,8 +62,7 @@ def solution():
* grid[i + 2][j + 2] * grid[i + 2][j + 2]
* grid[i + 3][j + 3] * grid[i + 3][j + 3]
) )
if temp > maximum: maximum = max(maximum, temp)
maximum = temp
# diagonal 2 # diagonal 2
for i in range(17): for i in range(17):
@ -76,8 +73,7 @@ def solution():
* grid[i + 2][j - 2] * grid[i + 2][j - 2]
* grid[i + 3][j - 3] * grid[i + 3][j - 3]
) )
if temp > maximum: maximum = max(maximum, temp)
maximum = temp
return maximum return maximum

View File

@ -46,8 +46,7 @@ def calculate_turn_around_time(
i = 0 i = 0
while finished_process[i] == 1: while finished_process[i] == 1:
i += 1 i += 1
if current_time < arrival_time[i]: current_time = max(current_time, arrival_time[i])
current_time = arrival_time[i]
response_ratio = 0 response_ratio = 0
# Index showing the location of the process being performed # Index showing the location of the process being performed

View File

@ -66,8 +66,7 @@ def calculate_waitingtime(
finar = finish_time - arrival_time[short] finar = finish_time - arrival_time[short]
waiting_time[short] = finar - burst_time[short] waiting_time[short] = finar - burst_time[short]
if waiting_time[short] < 0: waiting_time[short] = max(waiting_time[short], 0)
waiting_time[short] = 0
# Increment time # Increment time
increment_time += 1 increment_time += 1