Skip to content

Commit 4427859

Browse files
Merge branch 'master' into add-unit-tests
2 parents d64df51 + 544f48f commit 4427859

40 files changed

+899
-211
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
12+
- uses: actions/checkout@v5
1313
- uses: astral-sh/setup-uv@v6
1414
with:
1515
enable-cache: true

.github/workflows/devcontainer_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v5
1616
- uses: devcontainers/[email protected]
1717
with:
1818
push: never

.github/workflows/directory_writer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
directory_writer:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v4
9+
- uses: actions/checkout@v5
1010
with:
1111
fetch-depth: 0
1212
- uses: actions/setup-python@v5

.github/workflows/project_euler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
project-euler:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v4
17+
- uses: actions/checkout@v5
1818
- uses: astral-sh/setup-uv@v6
1919
- uses: actions/setup-python@v5
2020
with:
@@ -24,7 +24,7 @@ jobs:
2424
validate-solutions:
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v4
27+
- uses: actions/checkout@v5
2828
- uses: astral-sh/setup-uv@v6
2929
- uses: actions/setup-python@v5
3030
with:

.github/workflows/ruff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
ruff:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v5
1515
- uses: astral-sh/setup-uv@v6
1616
- run: uvx ruff check --output-format=github .

.github/workflows/sphinx.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
build_docs:
2626
runs-on: ubuntu-24.04-arm
2727
steps:
28-
- uses: actions/checkout@v4
28+
- uses: actions/checkout@v5
2929
- uses: astral-sh/setup-uv@v6
3030
- uses: actions/setup-python@v5
3131
with:
@@ -34,7 +34,7 @@ jobs:
3434
- run: uv sync --group=docs
3535
- uses: actions/configure-pages@v5
3636
- run: uv run sphinx-build -c docs . docs/_build/html
37-
- uses: actions/upload-pages-artifact@v3
37+
- uses: actions/upload-pages-artifact@v4
3838
with:
3939
path: docs/_build/html
4040

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v5.0.0
3+
rev: v6.0.0
44
hooks:
55
- id: check-executables-have-shebangs
66
- id: check-toml
@@ -16,7 +16,7 @@ repos:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.12.5
19+
rev: v0.12.11
2020
hooks:
2121
- id: ruff-check
2222
- id: ruff-format
@@ -47,7 +47,7 @@ repos:
4747
- id: validate-pyproject
4848

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

DIRECTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [Combination Sum](backtracking/combination_sum.py)
1313
* [Crossword Puzzle Solver](backtracking/crossword_puzzle_solver.py)
1414
* [Generate Parentheses](backtracking/generate_parentheses.py)
15+
* [Generate Parentheses Iterative](backtracking/generate_parentheses_iterative.py)
1516
* [Hamiltonian Cycle](backtracking/hamiltonian_cycle.py)
1617
* [Knight Tour](backtracking/knight_tour.py)
1718
* [Match Word Pattern](backtracking/match_word_pattern.py)
@@ -174,6 +175,7 @@
174175

175176
## Data Compression
176177
* [Burrows Wheeler](data_compression/burrows_wheeler.py)
178+
* [Coordinate Compression](data_compression/coordinate_compression.py)
177179
* [Huffman](data_compression/huffman.py)
178180
* [Lempel Ziv](data_compression/lempel_ziv.py)
179181
* [Lempel Ziv Decompress](data_compression/lempel_ziv_decompress.py)
@@ -723,6 +725,7 @@
723725
* [Secant Method](maths/numerical_analysis/secant_method.py)
724726
* [Simpson Rule](maths/numerical_analysis/simpson_rule.py)
725727
* [Square Root](maths/numerical_analysis/square_root.py)
728+
* [Weierstrass Method](maths/numerical_analysis/weierstrass_method.py)
726729
* [Odd Sieve](maths/odd_sieve.py)
727730
* [Perfect Cube](maths/perfect_cube.py)
728731
* [Perfect Number](maths/perfect_number.py)
@@ -956,6 +959,7 @@
956959
* [Sol1](project_euler/problem_009/sol1.py)
957960
* [Sol2](project_euler/problem_009/sol2.py)
958961
* [Sol3](project_euler/problem_009/sol3.py)
962+
* [Sol4](project_euler/problem_009/sol4.py)
959963
* Problem 010
960964
* [Sol1](project_euler/problem_010/sol1.py)
961965
* [Sol2](project_euler/problem_010/sol2.py)
@@ -1266,6 +1270,7 @@
12661270
* [Comb Sort](sorts/comb_sort.py)
12671271
* [Counting Sort](sorts/counting_sort.py)
12681272
* [Cycle Sort](sorts/cycle_sort.py)
1273+
* [Cyclic Sort](sorts/cyclic_sort.py)
12691274
* [Double Sort](sorts/double_sort.py)
12701275
* [Dutch National Flag Sort](sorts/dutch_national_flag_sort.py)
12711276
* [Exchange Sort](sorts/exchange_sort.py)
@@ -1296,6 +1301,7 @@
12961301
* [Shell Sort](sorts/shell_sort.py)
12971302
* [Shrink Shell Sort](sorts/shrink_shell_sort.py)
12981303
* [Slowsort](sorts/slowsort.py)
1304+
* [Stalin Sort](sorts/stalin_sort.py)
12991305
* [Stooge Sort](sorts/stooge_sort.py)
13001306
* [Strand Sort](sorts/strand_sort.py)
13011307
* [Tim Sort](sorts/tim_sort.py)

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<img src="https://raw.githubusercontent.com/TheAlgorithms/website/1cd824df116b27029f17c2d1b42d81731f28a920/public/logo.svg" height="100">
55
</a>
66
<h1><a href="https://github.com/TheAlgorithms/">The Algorithms</a> - Python</h1>
7+
78
<!-- Labels: -->
89
<!-- First row: -->
910
<a href="https://gitpod.io/#https://github.com/TheAlgorithms/Python">
@@ -19,6 +20,7 @@
1920
<a href="https://gitter.im/TheAlgorithms/community">
2021
<img src="https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square" height="20" alt="Gitter chat">
2122
</a>
23+
2224
<!-- Second row: -->
2325
<br>
2426
<a href="https://github.com/TheAlgorithms/Python/actions">
@@ -27,23 +29,24 @@
2729
<a href="https://github.com/pre-commit/pre-commit">
2830
<img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" height="20" alt="pre-commit">
2931
</a>
30-
<a href="https://github.com/psf/black">
31-
<img src="https://img.shields.io/static/v1?label=code%20style&message=black&color=black&style=flat-square" height="20" alt="code style: black">
32+
<a href="https://docs.astral.sh/ruff/formatter/">
33+
<img src="https://img.shields.io/static/v1?label=code%20style&message=ruff&color=black&style=flat-square" height="20" alt="code style: black">
3234
</a>
35+
3336
<!-- Short description: -->
34-
<h3>All algorithms implemented in Python - for education</h3>
37+
<h3>All algorithms implemented in Python - for education 📚</h3>
3538
</div>
3639

3740
Implementations are for learning purposes only. They may be less efficient than the implementations in the Python standard library. Use them at your discretion.
3841

39-
## Getting Started
42+
## 🚀 Getting Started
4043

41-
Read through our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
44+
📋 Read through our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
4245

43-
## Community Channels
46+
## 🌐 Community Channels
4447

4548
We are on [Discord](https://the-algorithms.com/discord) and [Gitter](https://gitter.im/TheAlgorithms/community)! Community channels are a great way for you to ask questions and get help. Please join us!
4649

47-
## List of Algorithms
50+
## 📜 List of Algorithms
4851

4952
See our [directory](DIRECTORY.md) for easier navigation and a better overview of the project.

backtracking/combination_sum.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,18 @@ def combination_sum(candidates: list, target: int) -> list:
4747
>>> combination_sum([-8, 2.3, 0], 1)
4848
Traceback (most recent call last):
4949
...
50-
RecursionError: maximum recursion depth exceeded
50+
ValueError: All elements in candidates must be non-negative
51+
>>> combination_sum([], 1)
52+
Traceback (most recent call last):
53+
...
54+
ValueError: Candidates list should not be empty
5155
"""
56+
if not candidates:
57+
raise ValueError("Candidates list should not be empty")
58+
59+
if any(x < 0 for x in candidates):
60+
raise ValueError("All elements in candidates must be non-negative")
61+
5262
path = [] # type: list[int]
5363
answer = [] # type: list[int]
5464
backtrack(candidates, path, answer, target, 0)

0 commit comments

Comments
 (0)