Skip to content

Commit 3e30751

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 868f619 commit 3e30751

File tree

11 files changed

+51
-12
lines changed

11 files changed

+51
-12
lines changed

data_structures/arrays/sudoku_solver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def eliminate(values, s, d):
9494
return False ## Contradiction: no place for this value
9595
# d can only be in one place in unit; assign it there
9696
elif len(dplaces) == 1 and not assign(values, dplaces[0], d):
97-
return False
97+
return False
9898
return values
9999

100100

data_structures/stacks/balanced_parentheses.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ def balanced_parentheses(parentheses: str) -> bool:
1919
for bracket in parentheses:
2020
if bracket in bracket_pairs:
2121
stack.push(bracket)
22-
elif bracket in (")", "]", "}") and stack.is_empty() or bracket_pairs[stack.pop()] != bracket:
22+
elif (
23+
bracket in (")", "]", "}")
24+
and stack.is_empty()
25+
or bracket_pairs[stack.pop()] != bracket
26+
):
2327
return False
2428
return stack.is_empty()
2529

graphs/a_star.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ def search(
7575
for i in range(len(DIRECTIONS)): # to try out different valid actions
7676
x2 = x + DIRECTIONS[i][0]
7777
y2 = y + DIRECTIONS[i][1]
78-
if x2 >= 0 and x2 < len(grid) and y2 >= 0 and y2 < len(grid[0]) and closed[x2][y2] == 0 and grid[x2][y2] == 0:
78+
if (
79+
x2 >= 0
80+
and x2 < len(grid)
81+
and y2 >= 0
82+
and y2 < len(grid[0])
83+
and closed[x2][y2] == 0
84+
and grid[x2][y2] == 0
85+
):
7986
g2 = g + cost
8087
f2 = g2 + heuristic[x2][y2]
8188
cell.append([f2, g2, x2, y2])

graphs/bi_directional_dijkstra.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def pass_and_relaxation(
3636
queue.put((new_cost_f, nxt))
3737
cst_fwd[nxt] = new_cost_f
3838
parent[nxt] = v
39-
if nxt in visited_backward and cst_fwd[v] + d + cst_bwd[nxt] < shortest_distance:
39+
if (
40+
nxt in visited_backward
41+
and cst_fwd[v] + d + cst_bwd[nxt] < shortest_distance
42+
):
4043
shortest_distance = cst_fwd[v] + d + cst_bwd[nxt]
4144
return shortest_distance
4245

project_euler/problem_033/sol1.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ def fraction_list(digit_len: int) -> list[str]:
4444
last_digit = int("1" + "0" * digit_len)
4545
for num in range(den, last_digit):
4646
while den <= 99:
47-
if (num != den) and (num % 10 == den // 10) and (den % 10 != 0) and is_digit_cancelling(num, den):
47+
if (
48+
(num != den)
49+
and (num % 10 == den // 10)
50+
and (den % 10 != 0)
51+
and is_digit_cancelling(num, den)
52+
):
4853
solutions.append(f"{num}/{den}")
4954
den += 1
5055
num += 1

project_euler/problem_037/sol1.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ def validate(n: int) -> bool:
8585
>>> validate(3797)
8686
True
8787
"""
88-
if len(str(n)) > 3 and (not is_prime(int(str(n)[-3:])) or not is_prime(int(str(n)[:3]))):
89-
return False
88+
if len(str(n)) > 3 and (
89+
not is_prime(int(str(n)[-3:])) or not is_prime(int(str(n)[:3]))
90+
):
91+
return False
9092
return True
9193

9294

project_euler/problem_107/sol1.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def prims_algorithm(self) -> Graph:
8181
while len(subgraph.vertices) < len(self.vertices):
8282
min_weight = max(self.edges.values()) + 1
8383
for edge, weight in self.edges.items():
84-
if (edge[0] in subgraph.vertices) ^ (edge[1] in subgraph.vertices) and weight < min_weight:
84+
if (edge[0] in subgraph.vertices) ^ (
85+
edge[1] in subgraph.vertices
86+
) and weight < min_weight:
8587
min_edge = edge
8688
min_weight = weight
8789

project_euler/problem_207/sol1.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ def solution(max_proportion: float = 1 / 12345) -> int:
8888
total_partitions += 1
8989
if check_partition_perfect(partition_candidate):
9090
perfect_partitions += 1
91-
if perfect_partitions > 0 and perfect_partitions / total_partitions < max_proportion:
91+
if (
92+
perfect_partitions > 0
93+
and perfect_partitions / total_partitions < max_proportion
94+
):
9295
return int(partition_candidate)
9396
integer += 1
9497

scheduling/shortest_job_first.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def calculate_waitingtime(
3737
# Process until all processes are completed
3838
while complete != no_of_processes:
3939
for j in range(no_of_processes):
40-
if arrival_time[j] <= increment_time and remaining_time[j] > 0 and remaining_time[j] < minm:
40+
if (
41+
arrival_time[j] <= increment_time
42+
and remaining_time[j] > 0
43+
and remaining_time[j] < minm
44+
):
4145
minm = remaining_time[j]
4246
short = j
4347
check = True

scripts/validate_solutions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def added_solution_file_path() -> list[pathlib.Path]:
7272

7373
def collect_solution_file_paths() -> list[pathlib.Path]:
7474
# Return only if there are any, otherwise default to all solutions
75-
if os.environ.get("CI") and os.environ.get("GITHUB_EVENT_NAME") == "pull_request" and (filepaths := added_solution_file_path()):
75+
if (
76+
os.environ.get("CI")
77+
and os.environ.get("GITHUB_EVENT_NAME") == "pull_request"
78+
and (filepaths := added_solution_file_path())
79+
):
7680
return filepaths
7781
return all_solution_file_paths()
7882

web_programming/emails_from_url.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None
3131
# Check the list of defined attributes.
3232
for name, value in attrs:
3333
# If href is defined, not empty nor # print it and not already in urls.
34-
if name == "href" and value != "#" and value != "" and value not in self.urls:
34+
if (
35+
name == "href"
36+
and value != "#"
37+
and value != ""
38+
and value not in self.urls
39+
):
3540
url = parse.urljoin(self.domain, value)
3641
self.urls.append(url)
3742

0 commit comments

Comments
 (0)