Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 1, 2024
1 parent 868f619 commit 3e30751
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion data_structures/arrays/sudoku_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def eliminate(values, s, d):
return False ## Contradiction: no place for this value
# d can only be in one place in unit; assign it there
elif len(dplaces) == 1 and not assign(values, dplaces[0], d):
return False
return False
return values


Expand Down
6 changes: 5 additions & 1 deletion data_structures/stacks/balanced_parentheses.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def balanced_parentheses(parentheses: str) -> bool:
for bracket in parentheses:
if bracket in bracket_pairs:
stack.push(bracket)
elif bracket in (")", "]", "}") and stack.is_empty() or bracket_pairs[stack.pop()] != bracket:
elif (
bracket in (")", "]", "}")
and stack.is_empty()
or bracket_pairs[stack.pop()] != bracket
):
return False
return stack.is_empty()

Expand Down
9 changes: 8 additions & 1 deletion graphs/a_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ def search(
for i in range(len(DIRECTIONS)): # to try out different valid actions
x2 = x + DIRECTIONS[i][0]
y2 = y + DIRECTIONS[i][1]
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:
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
):
g2 = g + cost
f2 = g2 + heuristic[x2][y2]
cell.append([f2, g2, x2, y2])
Expand Down
5 changes: 4 additions & 1 deletion graphs/bi_directional_dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def pass_and_relaxation(
queue.put((new_cost_f, nxt))
cst_fwd[nxt] = new_cost_f
parent[nxt] = v
if nxt in visited_backward and cst_fwd[v] + d + cst_bwd[nxt] < shortest_distance:
if (
nxt in visited_backward
and cst_fwd[v] + d + cst_bwd[nxt] < shortest_distance
):
shortest_distance = cst_fwd[v] + d + cst_bwd[nxt]
return shortest_distance

Expand Down
7 changes: 6 additions & 1 deletion project_euler/problem_033/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def fraction_list(digit_len: int) -> list[str]:
last_digit = int("1" + "0" * digit_len)
for num in range(den, last_digit):
while den <= 99:
if (num != den) and (num % 10 == den // 10) and (den % 10 != 0) and is_digit_cancelling(num, den):
if (
(num != den)
and (num % 10 == den // 10)
and (den % 10 != 0)
and is_digit_cancelling(num, den)
):
solutions.append(f"{num}/{den}")
den += 1
num += 1
Expand Down
6 changes: 4 additions & 2 deletions project_euler/problem_037/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def validate(n: int) -> bool:
>>> validate(3797)
True
"""
if len(str(n)) > 3 and (not is_prime(int(str(n)[-3:])) or not is_prime(int(str(n)[:3]))):
return False
if len(str(n)) > 3 and (
not is_prime(int(str(n)[-3:])) or not is_prime(int(str(n)[:3]))
):
return False
return True


Expand Down
4 changes: 3 additions & 1 deletion project_euler/problem_107/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def prims_algorithm(self) -> Graph:
while len(subgraph.vertices) < len(self.vertices):
min_weight = max(self.edges.values()) + 1
for edge, weight in self.edges.items():
if (edge[0] in subgraph.vertices) ^ (edge[1] in subgraph.vertices) and weight < min_weight:
if (edge[0] in subgraph.vertices) ^ (
edge[1] in subgraph.vertices
) and weight < min_weight:
min_edge = edge
min_weight = weight

Expand Down
5 changes: 4 additions & 1 deletion project_euler/problem_207/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def solution(max_proportion: float = 1 / 12345) -> int:
total_partitions += 1
if check_partition_perfect(partition_candidate):
perfect_partitions += 1
if perfect_partitions > 0 and perfect_partitions / total_partitions < max_proportion:
if (
perfect_partitions > 0
and perfect_partitions / total_partitions < max_proportion
):
return int(partition_candidate)
integer += 1

Expand Down
6 changes: 5 additions & 1 deletion scheduling/shortest_job_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def calculate_waitingtime(
# Process until all processes are completed
while complete != no_of_processes:
for j in range(no_of_processes):
if arrival_time[j] <= increment_time and remaining_time[j] > 0 and remaining_time[j] < minm:
if (
arrival_time[j] <= increment_time
and remaining_time[j] > 0
and remaining_time[j] < minm
):
minm = remaining_time[j]
short = j
check = True
Expand Down
6 changes: 5 additions & 1 deletion scripts/validate_solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def added_solution_file_path() -> list[pathlib.Path]:

def collect_solution_file_paths() -> list[pathlib.Path]:
# Return only if there are any, otherwise default to all solutions
if os.environ.get("CI") and os.environ.get("GITHUB_EVENT_NAME") == "pull_request" and (filepaths := added_solution_file_path()):
if (
os.environ.get("CI")
and os.environ.get("GITHUB_EVENT_NAME") == "pull_request"
and (filepaths := added_solution_file_path())
):
return filepaths
return all_solution_file_paths()

Expand Down
7 changes: 6 additions & 1 deletion web_programming/emails_from_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None
# Check the list of defined attributes.
for name, value in attrs:
# If href is defined, not empty nor # print it and not already in urls.
if name == "href" and value != "#" and value != "" and value not in self.urls:
if (
name == "href"
and value != "#"
and value != ""
and value not in self.urls
):
url = parse.urljoin(self.domain, value)
self.urls.append(url)

Expand Down

0 comments on commit 3e30751

Please sign in to comment.