Skip to content

Commit cae89c0

Browse files
authored
Merge branch 'TheAlgorithms:master' into master
2 parents f3fc655 + 0bcdfbd commit cae89c0

40 files changed

+1673
-123
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13+
- uses: astral-sh/setup-uv@v4
14+
with:
15+
enable-cache: true
16+
cache-dependency-glob: uv.lock
1317
- uses: actions/setup-python@v5
1418
with:
1519
python-version: 3.13
1620
allow-prereleases: true
17-
- uses: actions/cache@v4
18-
with:
19-
path: ~/.cache/pip
20-
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
21-
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip setuptools wheel
24-
python -m pip install pytest-cov -r requirements.txt
21+
- run: uv sync --group=test
2522
- name: Run tests
2623
# TODO: #8818 Re-enable quantum tests
27-
run: pytest
24+
run: uv run pytest
2825
--ignore=computer_vision/cnn_classification.py
2926
--ignore=docs/conf.py
3027
--ignore=dynamic_programming/k_means_clustering_tensorflow.py

.github/workflows/project_euler.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,21 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18+
- uses: astral-sh/setup-uv@v4
1819
- uses: actions/setup-python@v5
1920
with:
2021
python-version: 3.x
21-
- name: Install pytest and pytest-cov
22-
run: |
23-
python -m pip install --upgrade pip
24-
python -m pip install --upgrade numpy pytest pytest-cov
25-
- run: pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
22+
- run: uv sync --group=euler-validate --group=test
23+
- run: uv run pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
2624
validate-solutions:
2725
runs-on: ubuntu-latest
2826
steps:
2927
- uses: actions/checkout@v4
28+
- uses: astral-sh/setup-uv@v4
3029
- uses: actions/setup-python@v5
3130
with:
3231
python-version: 3.x
33-
- name: Install pytest and requests
34-
run: |
35-
python -m pip install --upgrade pip
36-
python -m pip install --upgrade numpy pytest requests
37-
- run: pytest scripts/validate_solutions.py
32+
- run: uv sync --group=euler-validate --group=test
33+
- run: uv run pytest scripts/validate_solutions.py
3834
env:
3935
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ruff.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
15-
- run: pip install --user ruff
16-
- run: ruff check --output-format=github .
15+
- uses: astral-sh/setup-uv@v4
16+
- run: uvx ruff check --output-format=github .

.github/workflows/sphinx.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ jobs:
2626
runs-on: ubuntu-latest
2727
steps:
2828
- uses: actions/checkout@v4
29+
- uses: astral-sh/setup-uv@v4
2930
- uses: actions/setup-python@v5
3031
with:
3132
python-version: 3.13
3233
allow-prereleases: true
33-
- run: pip install --upgrade pip
34-
- run: pip install myst-parser sphinx-autoapi sphinx-pyproject
34+
- run: uv sync --group=docs
3535
- uses: actions/configure-pages@v5
36-
- run: sphinx-build -c docs . docs/_build/html
36+
- run: uv run sphinx-build -c docs . docs/_build/html
3737
- uses: actions/upload-pages-artifact@v3
3838
with:
3939
path: docs/_build/html

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.7.0
19+
rev: v0.8.1
2020
hooks:
2121
- id: ruff
2222
- id: ruff-format
@@ -29,7 +29,7 @@ repos:
2929
- tomli
3030

3131
- repo: https://github.com/tox-dev/pyproject-fmt
32-
rev: "2.4.3"
32+
rev: "v2.5.0"
3333
hooks:
3434
- id: pyproject-fmt
3535

@@ -42,12 +42,12 @@ repos:
4242
pass_filenames: false
4343

4444
- repo: https://github.com/abravalheri/validate-pyproject
45-
rev: v0.21
45+
rev: v0.23
4646
hooks:
4747
- id: validate-pyproject
4848

4949
- repo: https://github.com/pre-commit/mirrors-mypy
50-
rev: v1.12.1
50+
rev: v1.13.0
5151
hooks:
5252
- id: mypy
5353
args:

DIRECTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@
794794
* [Cramers Rule 2X2](matrix/cramers_rule_2x2.py)
795795
* [Inverse Of Matrix](matrix/inverse_of_matrix.py)
796796
* [Largest Square Area In Matrix](matrix/largest_square_area_in_matrix.py)
797+
* [Matrix Based Game](matrix/matrix_based_game.py)
797798
* [Matrix Class](matrix/matrix_class.py)
798799
* [Matrix Equalization](matrix/matrix_equalization.py)
799800
* [Matrix Multiplication Recursion](matrix/matrix_multiplication_recursion.py)

cellular_automata/conways_game_of_life.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ def new_generation(cells: list[list[int]]) -> list[list[int]]:
5858
# 3. All other live cells die in the next generation.
5959
# Similarly, all other dead cells stay dead.
6060
alive = cells[i][j] == 1
61-
if (
62-
(alive and 2 <= neighbour_count <= 3)
63-
or not alive
64-
and neighbour_count == 3
61+
if (alive and 2 <= neighbour_count <= 3) or (
62+
not alive and neighbour_count == 3
6563
):
6664
next_generation_row.append(1)
6765
else:

ciphers/playfair_cipher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from collections.abc import Generator, Iterable
2525

2626

27-
def chunker(seq: Iterable[str], size: int) -> Generator[tuple[str, ...], None, None]:
27+
def chunker(seq: Iterable[str], size: int) -> Generator[tuple[str, ...]]:
2828
it = iter(seq)
2929
while True:
3030
chunk = tuple(itertools.islice(it, size))

ciphers/simple_keyword_cypher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def remove_duplicates(key: str) -> str:
1010

1111
key_no_dups = ""
1212
for ch in key:
13-
if ch == " " or ch not in key_no_dups and ch.isalpha():
13+
if ch == " " or (ch not in key_no_dups and ch.isalpha()):
1414
key_no_dups += ch
1515
return key_no_dups
1616

ciphers/transposition_cipher.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ def decrypt_message(key: int, message: str) -> str:
5252
plain_text[col] += symbol
5353
col += 1
5454

55-
if (
56-
(col == num_cols)
57-
or (col == num_cols - 1)
58-
and (row >= num_rows - num_shaded_boxes)
55+
if (col == num_cols) or (
56+
(col == num_cols - 1) and (row >= num_rows - num_shaded_boxes)
5957
):
6058
col = 0
6159
row += 1

0 commit comments

Comments
 (0)