Compare commits

...

3 Commits

Author SHA1 Message Date
Caeden Perelli-Harris
9e08c7726d
Small docstring time complexity fix in number_container _system (#8875)
* fix: Write time is O(log n) not O(n log n)

* chore: Update pre-commit ruff version

* revert: Undo previous commit
2023-07-22 12:34:19 +02:00
Tianyi Zheng
f7531d9874
Add note in CONTRIBUTING.md about not asking to be assigned to issues (#8871)
* Add note in CONTRIBUTING.md about not asking to be assigned to issues

Add a paragraph to CONTRIBUTING.md explicitly asking contributors to not ask to be assigned to issues

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2023-07-22 12:11:04 +02:00
Caeden Perelli-Harris
93fb169627
[Upgrade Ruff] Fix all errors raised from ruff (#8879)
* chore: Fix tests

* chore: Fix failing ruff

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: Fix ruff errors

* chore: Fix ruff errors

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update cellular_automata/game_of_life.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* chore: Update ruff version in pre-commit

* chore: Fix ruff errors

* Update edmonds_karp_multiple_source_and_sink.py

* Update factorial.py

* Update primelib.py

* Update min_cost_string_conversion.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2023-07-22 12:05:10 +02:00
16 changed files with 35 additions and 31 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.0.278 rev: v0.0.280
hooks: hooks:
- id: ruff - id: ruff

View File

@ -25,6 +25,8 @@ We appreciate any contribution, from fixing a grammar mistake in a comment to im
Your contribution will be tested by our [automated testing on GitHub Actions](https://github.com/TheAlgorithms/Python/actions) to save time and mental energy. After you have submitted your pull request, you should see the GitHub Actions tests start to run at the bottom of your submission page. If those tests fail, then click on the ___details___ button try to read through the GitHub Actions output to understand the failure. If you do not understand, please leave a comment on your submission page and a community member will try to help. Your contribution will be tested by our [automated testing on GitHub Actions](https://github.com/TheAlgorithms/Python/actions) to save time and mental energy. After you have submitted your pull request, you should see the GitHub Actions tests start to run at the bottom of your submission page. If those tests fail, then click on the ___details___ button try to read through the GitHub Actions output to understand the failure. If you do not understand, please leave a comment on your submission page and a community member will try to help.
If you are interested in resolving an [open issue](https://github.com/TheAlgorithms/Python/issues), simply make a pull request with your proposed fix. __We do not assign issues in this repo__ so please do not ask for permission to work on an issue.
Please help us keep our issue list small by adding `Fixes #{$ISSUE_NUMBER}` to the description of pull requests that resolve open issues. Please help us keep our issue list small by adding `Fixes #{$ISSUE_NUMBER}` to the description of pull requests that resolve open issues.
For example, if your pull request fixes issue #10, then please add the following to its description: For example, if your pull request fixes issue #10, then please add the following to its description:
``` ```

View File

@ -98,7 +98,7 @@ def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool:
if pt: if pt:
if alive < 2: if alive < 2:
state = False state = False
elif alive == 2 or alive == 3: elif alive in {2, 3}:
state = True state = True
elif alive > 3: elif alive > 3:
state = False state = False

View File

@ -152,7 +152,7 @@ class RedBlackTree:
self.grandparent.color = 1 self.grandparent.color = 1
self.grandparent._insert_repair() self.grandparent._insert_repair()
def remove(self, label: int) -> RedBlackTree: def remove(self, label: int) -> RedBlackTree: # noqa: PLR0912
"""Remove label from this tree.""" """Remove label from this tree."""
if self.label == label: if self.label == label:
if self.left and self.right: if self.left and self.right:

View File

@ -156,7 +156,7 @@ class RadixNode:
del self.nodes[word[0]] del self.nodes[word[0]]
# We merge the current node with its only child # We merge the current node with its only child
if len(self.nodes) == 1 and not self.is_leaf: if len(self.nodes) == 1 and not self.is_leaf:
merging_node = list(self.nodes.values())[0] merging_node = next(iter(self.nodes.values()))
self.is_leaf = merging_node.is_leaf self.is_leaf = merging_node.is_leaf
self.prefix += merging_node.prefix self.prefix += merging_node.prefix
self.nodes = merging_node.nodes self.nodes = merging_node.nodes
@ -165,7 +165,7 @@ class RadixNode:
incoming_node.is_leaf = False incoming_node.is_leaf = False
# If there is 1 edge, we merge it with its child # If there is 1 edge, we merge it with its child
else: else:
merging_node = list(incoming_node.nodes.values())[0] merging_node = next(iter(incoming_node.nodes.values()))
incoming_node.is_leaf = merging_node.is_leaf incoming_node.is_leaf = merging_node.is_leaf
incoming_node.prefix += merging_node.prefix incoming_node.prefix += merging_node.prefix
incoming_node.nodes = merging_node.nodes incoming_node.nodes = merging_node.nodes

View File

@ -266,7 +266,7 @@ def convex_hull_bf(points: list[Point]) -> list[Point]:
points_left_of_ij = points_right_of_ij = False points_left_of_ij = points_right_of_ij = False
ij_part_of_convex_hull = True ij_part_of_convex_hull = True
for k in range(n): for k in range(n):
if k != i and k != j: if k not in {i, j}:
det_k = _det(points[i], points[j], points[k]) det_k = _det(points[i], points[j], points[k])
if det_k > 0: if det_k > 0:

View File

@ -39,7 +39,7 @@ class DirectedGraph:
stack = [] stack = []
visited = [] visited = []
if s == -2: if s == -2:
s = list(self.graph)[0] s = next(iter(self.graph))
stack.append(s) stack.append(s)
visited.append(s) visited.append(s)
ss = s ss = s
@ -87,7 +87,7 @@ class DirectedGraph:
d = deque() d = deque()
visited = [] visited = []
if s == -2: if s == -2:
s = list(self.graph)[0] s = next(iter(self.graph))
d.append(s) d.append(s)
visited.append(s) visited.append(s)
while d: while d:
@ -114,7 +114,7 @@ class DirectedGraph:
stack = [] stack = []
visited = [] visited = []
if s == -2: if s == -2:
s = list(self.graph)[0] s = next(iter(self.graph))
stack.append(s) stack.append(s)
visited.append(s) visited.append(s)
ss = s ss = s
@ -146,7 +146,7 @@ class DirectedGraph:
def cycle_nodes(self): def cycle_nodes(self):
stack = [] stack = []
visited = [] visited = []
s = list(self.graph)[0] s = next(iter(self.graph))
stack.append(s) stack.append(s)
visited.append(s) visited.append(s)
parent = -2 parent = -2
@ -199,7 +199,7 @@ class DirectedGraph:
def has_cycle(self): def has_cycle(self):
stack = [] stack = []
visited = [] visited = []
s = list(self.graph)[0] s = next(iter(self.graph))
stack.append(s) stack.append(s)
visited.append(s) visited.append(s)
parent = -2 parent = -2
@ -305,7 +305,7 @@ class Graph:
stack = [] stack = []
visited = [] visited = []
if s == -2: if s == -2:
s = list(self.graph)[0] s = next(iter(self.graph))
stack.append(s) stack.append(s)
visited.append(s) visited.append(s)
ss = s ss = s
@ -353,7 +353,7 @@ class Graph:
d = deque() d = deque()
visited = [] visited = []
if s == -2: if s == -2:
s = list(self.graph)[0] s = next(iter(self.graph))
d.append(s) d.append(s)
visited.append(s) visited.append(s)
while d: while d:
@ -371,7 +371,7 @@ class Graph:
def cycle_nodes(self): def cycle_nodes(self):
stack = [] stack = []
visited = [] visited = []
s = list(self.graph)[0] s = next(iter(self.graph))
stack.append(s) stack.append(s)
visited.append(s) visited.append(s)
parent = -2 parent = -2
@ -424,7 +424,7 @@ class Graph:
def has_cycle(self): def has_cycle(self):
stack = [] stack = []
visited = [] visited = []
s = list(self.graph)[0] s = next(iter(self.graph))
stack.append(s) stack.append(s)
visited.append(s) visited.append(s)
parent = -2 parent = -2

View File

@ -113,7 +113,7 @@ class PushRelabelExecutor(MaximumFlowAlgorithmExecutor):
vertices_list = [ vertices_list = [
i i
for i in range(self.verticies_count) for i in range(self.verticies_count)
if i != self.source_index and i != self.sink_index if i not in {self.source_index, self.sink_index}
] ]
# move through list # move through list

View File

@ -55,7 +55,7 @@ def factorial_recursive(n: int) -> int:
raise ValueError("factorial() only accepts integral values") raise ValueError("factorial() only accepts integral values")
if n < 0: if n < 0:
raise ValueError("factorial() not defined for negative values") raise ValueError("factorial() not defined for negative values")
return 1 if n == 0 or n == 1 else n * factorial(n - 1) return 1 if n in {0, 1} else n * factorial(n - 1)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -154,7 +154,7 @@ def prime_factorization(number):
quotient = number quotient = number
if number == 0 or number == 1: if number in {0, 1}:
ans.append(number) ans.append(number)
# if 'number' not prime then builds the prime factorization of 'number' # if 'number' not prime then builds the prime factorization of 'number'

View File

@ -253,7 +253,7 @@ def find_unit_clauses(
unit_symbols = [] unit_symbols = []
for clause in clauses: for clause in clauses:
if len(clause) == 1: if len(clause) == 1:
unit_symbols.append(list(clause.literals.keys())[0]) unit_symbols.append(next(iter(clause.literals.keys())))
else: else:
f_count, n_count = 0, 0 f_count, n_count = 0, 0
for literal, value in clause.literals.items(): for literal, value in clause.literals.items():

View File

@ -1,6 +1,6 @@
""" """
A number container system that uses binary search to delete and insert values into A number container system that uses binary search to delete and insert values into
arrays with O(n logn) write times and O(1) read times. arrays with O(log n) write times and O(1) read times.
This container system holds integers at indexes. This container system holds integers at indexes.

View File

@ -28,12 +28,16 @@ def solution() -> int:
31875000 31875000
""" """
return [ return next(
iter(
[
a * b * (1000 - a - b) a * b * (1000 - a - b)
for a in range(1, 999) for a in range(1, 999)
for b in range(a, 999) for b in range(a, 999)
if (a * a + b * b == (1000 - a - b) ** 2) if (a * a + b * b == (1000 - a - b) ** 2)
][0] ]
)
)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -107,7 +107,7 @@ def ripple_adder(
res = qiskit.execute(circuit, backend, shots=1).result() res = qiskit.execute(circuit, backend, shots=1).result()
# The result is in binary. Convert it back to int # The result is in binary. Convert it back to int
return int(list(res.get_counts())[0], 2) return int(next(iter(res.get_counts())), 2)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -61,7 +61,7 @@ def assemble_transformation(ops: list[list[str]], i: int, j: int) -> list[str]:
if i == 0 and j == 0: if i == 0 and j == 0:
return [] return []
else: else:
if ops[i][j][0] == "C" or ops[i][j][0] == "R": if ops[i][j][0] in {"C", "R"}:
seq = assemble_transformation(ops, i - 1, j - 1) seq = assemble_transformation(ops, i - 1, j - 1)
seq.append(ops[i][j]) seq.append(ops[i][j])
return seq return seq

View File

@ -90,9 +90,7 @@ def convert(number: int) -> str:
else: else:
addition = "" addition = ""
if counter in placevalue: if counter in placevalue:
if current == 0 and ((temp_num % 100) // 10) == 0: if current != 0 and ((temp_num % 100) // 10) != 0:
addition = ""
else:
addition = placevalue[counter] addition = placevalue[counter]
if ((temp_num % 100) // 10) == 1: if ((temp_num % 100) // 10) == 1:
words = teens[current] + addition + words words = teens[current] + addition + words