Skip to content

Commit 25ff4d8

Browse files
authored
Merge branch 'master' into patch-1
2 parents 12bcdb8 + 840ca00 commit 25ff4d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1094
-118
lines changed

.github/workflows/sphinx.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
python-version: 3.14
4040
allow-prereleases: true
4141
- run: uv sync --group=docs
42-
- uses: actions/configure-pages@v5
42+
- uses: actions/configure-pages@v6
4343
- run: uv run sphinx-build -c docs . docs/_build/html
4444
- uses: actions/upload-pages-artifact@v4
4545
with:
@@ -53,5 +53,5 @@ jobs:
5353
needs: build_docs
5454
runs-on: ubuntu-latest
5555
steps:
56-
- uses: actions/deploy-pages@v4
56+
- uses: actions/deploy-pages@v5
5757
id: deployment

.pre-commit-config.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ repos:
1414
- id: requirements-txt-fixer
1515

1616
- repo: https://github.com/MarcoGorelli/auto-walrus
17-
rev: 0.3.4
17+
rev: 0.4.1
1818
hooks:
1919
- id: auto-walrus
2020

2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.14.10
22+
rev: v0.15.4
2323
hooks:
2424
- id: ruff-check
2525
- id: ruff-format
@@ -32,7 +32,7 @@ repos:
3232
- tomli
3333

3434
- repo: https://github.com/tox-dev/pyproject-fmt
35-
rev: v2.11.1
35+
rev: v2.16.2
3636
hooks:
3737
- id: pyproject-fmt
3838

@@ -45,19 +45,19 @@ repos:
4545
pass_filenames: false
4646

4747
- repo: https://github.com/abravalheri/validate-pyproject
48-
rev: v0.24.1
48+
rev: v0.25
4949
hooks:
5050
- id: validate-pyproject
5151

52-
- repo: https://github.com/pre-commit/mirrors-mypy
53-
rev: v1.19.1
54-
hooks:
55-
- id: mypy
56-
args:
57-
- --explicit-package-bases
58-
- --ignore-missing-imports
59-
- --install-types
60-
- --non-interactive
52+
# - repo: https://github.com/pre-commit/mirrors-mypy
53+
# rev: v1.20.0
54+
# hooks:
55+
# - id: mypy
56+
# args:
57+
# - --explicit-package-bases
58+
# - --ignore-missing-imports
59+
# - --install-types
60+
# - --non-interactive
6161

6262
- repo: https://github.com/pre-commit/mirrors-prettier
6363
rev: v4.0.0-alpha.8

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ We want your work to be readable by others; therefore, we encourage you to note
159159
starting_value = int(input("Please enter a starting value: ").strip())
160160
```
161161

162-
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](http://mypy-lang.org) so run that locally before making your submission.
162+
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](https://mypy-lang.org) so run that locally before making your submission.
163163

164164
```python
165165
def sum_ab(a: int, b: int) -> int:

DIRECTORY.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@
469469

470470
## Geometry
471471
* [Geometry](geometry/geometry.py)
472+
* [Graham Scan](geometry/graham_scan.py)
473+
* [Jarvis March](geometry/jarvis_march.py)
474+
* Tests
475+
* [Test Graham Scan](geometry/tests/test_graham_scan.py)
476+
* [Test Jarvis March](geometry/tests/test_jarvis_march.py)
472477

473478
## Graphics
474479
* [Bezier Curve](graphics/bezier_curve.py)
@@ -881,6 +886,7 @@
881886
* [Quine](other/quine.py)
882887
* [Scoring Algorithm](other/scoring_algorithm.py)
883888
* [Sdes](other/sdes.py)
889+
* [Sliding Window Maximum](other/sliding_window_maximum.py)
884890
* [Tower Of Hanoi](other/tower_of_hanoi.py)
885891
* [Word Search](other/word_search.py)
886892

@@ -980,6 +986,7 @@
980986
* [Sol2](project_euler/problem_014/sol2.py)
981987
* Problem 015
982988
* [Sol1](project_euler/problem_015/sol1.py)
989+
* [Sol2](project_euler/problem_015/sol2.py)
983990
* Problem 016
984991
* [Sol1](project_euler/problem_016/sol1.py)
985992
* [Sol2](project_euler/problem_016/sol2.py)

backtracking/coloring.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ def color(graph: list[list[int]], max_colors: int) -> list[int]:
104104
>>> max_colors = 2
105105
>>> color(graph, max_colors)
106106
[]
107+
>>> color([], 2) # empty graph
108+
[]
109+
>>> color([[0]], 1) # single node, 1 color
110+
[0]
111+
>>> color([[0, 1], [1, 0]], 1) # 2 nodes, 1 color (impossible)
112+
[]
113+
>>> color([[0, 1], [1, 0]], 2) # 2 nodes, 2 colors (possible)
114+
[0, 1]
107115
"""
108116
colored_vertices = [-1] * len(graph)
109117

backtracking/generate_parentheses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def generate_parenthesis(n: int) -> list[str]:
6464
Example 2:
6565
>>> generate_parenthesis(1)
6666
['()']
67+
68+
Example 3:
69+
>>> generate_parenthesis(0)
70+
['']
6771
"""
6872

6973
result: list[str] = []

backtracking/generate_parentheses_iterative.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
def generate_parentheses_iterative(length: int) -> list:
1+
def generate_parentheses_iterative(length: int) -> list[str]:
22
"""
33
Generate all valid combinations of parentheses (Iterative Approach).
44
55
The algorithm works as follows:
66
1. Initialize an empty list to store the combinations.
77
2. Initialize a stack to keep track of partial combinations.
8-
3. Start with empty string and push it onstack along with the counts of '(' and ')'.
8+
3. Start with empty string and push it on stack along with
9+
the counts of '(' and ')'.
910
4. While the stack is not empty:
1011
a. Pop a partial combination and its open and close counts from the stack.
1112
b. If the combination length is equal to 2*length, add it to the result.
@@ -34,8 +35,11 @@ def generate_parentheses_iterative(length: int) -> list:
3435
>>> generate_parentheses_iterative(0)
3536
['']
3637
"""
37-
result = []
38-
stack = []
38+
if length == 0:
39+
return [""]
40+
41+
result: list[str] = []
42+
stack: list[tuple[str, int, int]] = []
3943

4044
# Each element in stack is a tuple (current_combination, open_count, close_count)
4145
stack.append(("", 0, 0))
@@ -45,6 +49,7 @@ def generate_parentheses_iterative(length: int) -> list:
4549

4650
if len(current_combination) == 2 * length:
4751
result.append(current_combination)
52+
continue
4853

4954
if open_count < length:
5055
stack.append((current_combination + "(", open_count + 1, close_count))

backtracking/n_queens.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def is_safe(board: list[list[int]], row: int, column: int) -> bool:
3333
False
3434
>>> is_safe([[0, 0, 1], [0, 0, 0], [0, 0, 0]], 1, 1)
3535
False
36+
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 1, 2)
37+
True
38+
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 2, 1)
39+
True
40+
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 0, 2)
41+
True
42+
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 2, 2)
43+
True
3644
"""
3745

3846
n = len(board) # Size of the board

backtracking/word_break.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def word_break(input_string: str, word_dict: set[str]) -> bool:
6666
6767
>>> word_break("catsandog", {"cats", "dog", "sand", "and", "cat"})
6868
False
69+
70+
>>> word_break("applepenapple", {})
71+
False
6972
"""
7073

7174
return backtrack(input_string, word_dict, 0)

ciphers/caesar_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def encrypt(input_string: str, key: int, alphabet: str | None = None) -> str:
4545
And our shift is ``2``
4646
4747
We can then encode the message, one letter at a time. ``H`` would become ``J``,
48-
since ``J`` is two letters away, and so on. If the shift is ever two large, or
48+
since ``J`` is two letters away, and so on. If the shift is ever too large, or
4949
our letter is at the end of the alphabet, we just start at the beginning
5050
(``Z`` would shift to ``a`` then ``b`` and so on).
5151

0 commit comments

Comments
 (0)