Skip to content
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions divide_and_conquer/closest_pair_of_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand Down
3 changes: 1 addition & 2 deletions graphs/kahns_algorithm_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion maths/find_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions maths/special_numbers/bell_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions matrix/tests/test_matrix_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
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)]
)
Expand All @@ -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)]
)
Expand All @@ -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)]
)
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions project_euler/problem_008/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 1 addition & 2 deletions project_euler/problem_009/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 1 addition & 2 deletions project_euler/problem_011/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 4 additions & 8 deletions project_euler/problem_011/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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


Expand Down
3 changes: 1 addition & 2 deletions scheduling/highest_response_ratio_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions scheduling/shortest_job_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down