Skip to content

Commit 911943b

Browse files
Merge branch 'master' into issue_fix
2 parents d8c8ace + 8439fa8 commit 911943b

File tree

128 files changed

+4337
-1020
lines changed

Some content is hidden

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

128 files changed

+4337
-1020
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# https://github.com/microsoft/vscode-dev-containers/blob/main/containers/python-3/README.md
2-
ARG VARIANT=3.12-bookworm
2+
ARG VARIANT=3.13-bookworm
33
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}
44
COPY requirements.txt /tmp/pip-tmp/
55
RUN python3 -m pip install --upgrade pip \

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Update 'VARIANT' to pick a Python version: 3, 3.11, 3.10, 3.9, 3.8
88
// Append -bullseye or -buster to pin to an OS version.
99
// Use -bullseye variants on local on arm64/Apple Silicon.
10-
"VARIANT": "3.12-bookworm",
10+
"VARIANT": "3.13-bookworm",
1111
}
1212
},
1313

.github/CODEOWNERS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
/.* @cclauss
1111

12-
# /arithmetic_analysis/
13-
1412
# /backtracking/
1513

1614
# /bit_manipulation/

.github/workflows/build.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,25 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13+
- uses: astral-sh/setup-uv@v5
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 six 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
28-
--ignore=quantum/q_fourier_transform.py
24+
run: uv run pytest
2925
--ignore=computer_vision/cnn_classification.py
26+
--ignore=docs/conf.py
3027
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
3128
--ignore=machine_learning/lstm/lstm_prediction.py
3229
--ignore=neural_network/input_data.py
3330
--ignore=project_euler/
31+
--ignore=quantum/q_fourier_transform.py
3432
--ignore=scripts/validate_solutions.py
3533
--cov-report=term-missing:skip-covered
3634
--cov=. .

.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@v5
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@v5
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@v5
16+
- run: uvx ruff check --output-format=github .

.github/workflows/sphinx.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: sphinx
2+
3+
on:
4+
# Triggers the workflow on push or pull request events but only for the "master" branch
5+
push:
6+
branches: ["master"]
7+
pull_request:
8+
branches: ["master"]
9+
# Or manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
build_docs:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: astral-sh/setup-uv@v5
30+
- uses: actions/setup-python@v5
31+
with:
32+
python-version: 3.13
33+
allow-prereleases: true
34+
- run: uv sync --group=docs
35+
- uses: actions/configure-pages@v5
36+
- run: uv run sphinx-build -c docs . docs/_build/html
37+
- uses: actions/upload-pages-artifact@v3
38+
with:
39+
path: docs/_build/html
40+
41+
deploy_docs:
42+
environment:
43+
name: github-pages
44+
url: ${{ steps.deployment.outputs.page_url }}
45+
if: github.event_name != 'pull_request'
46+
needs: build_docs
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/deploy-pages@v4
50+
id: deployment

.pre-commit-config.yaml

Lines changed: 5 additions & 5 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: v4.6.0
3+
rev: v5.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.6.8
19+
rev: v0.8.4
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.2.4"
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.20.2
45+
rev: v0.23
4646
hooks:
4747
- id: validate-pyproject
4848

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

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pre-commit run --all-files --show-diff-on-failure
7777

7878
We want your work to be readable by others; therefore, we encourage you to note the following:
7979

80-
- Please write in Python 3.12+. For instance: `print()` is a function in Python 3 so `print "Hello"` will *not* work but `print("Hello")` will.
80+
- Please write in Python 3.13+. For instance: `print()` is a function in Python 3 so `print "Hello"` will *not* work but `print("Hello")` will.
8181
- Please focus hard on the naming of functions, classes, and variables. Help your reader by using __descriptive names__ that can help you to remove redundant comments.
8282
- Single letter variable names are *old school* so please avoid them unless their life only spans a few lines.
8383
- Expand acronyms because `gcd()` is hard to understand but `greatest_common_divisor()` is not.
@@ -96,7 +96,7 @@ We want your work to be readable by others; therefore, we encourage you to note
9696

9797
```bash
9898
python3 -m pip install ruff # only required the first time
99-
ruff .
99+
ruff check
100100
```
101101

102102
- Original code submission require docstrings or comments to describe your work.

DIRECTORY.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* [Rat In Maze](backtracking/rat_in_maze.py)
2323
* [Sudoku](backtracking/sudoku.py)
2424
* [Sum Of Subsets](backtracking/sum_of_subsets.py)
25+
* [Word Break](backtracking/word_break.py)
26+
* [Word Ladder](backtracking/word_ladder.py)
2527
* [Word Search](backtracking/word_search.py)
2628

2729
## Bit Manipulation
@@ -98,6 +100,7 @@
98100
* [Elgamal Key Generator](ciphers/elgamal_key_generator.py)
99101
* [Enigma Machine2](ciphers/enigma_machine2.py)
100102
* [Fractionated Morse Cipher](ciphers/fractionated_morse_cipher.py)
103+
* [Gronsfeld Cipher](ciphers/gronsfeld_cipher.py)
101104
* [Hill Cipher](ciphers/hill_cipher.py)
102105
* [Mixed Keyword Cypher](ciphers/mixed_keyword_cypher.py)
103106
* [Mono Alphabetic Ciphers](ciphers/mono_alphabetic_ciphers.py)
@@ -166,6 +169,7 @@
166169
* [Prefix Conversions](conversions/prefix_conversions.py)
167170
* [Prefix Conversions String](conversions/prefix_conversions_string.py)
168171
* [Pressure Conversions](conversions/pressure_conversions.py)
172+
* [Rectangular To Polar](conversions/rectangular_to_polar.py)
169173
* [Rgb Cmyk Conversion](conversions/rgb_cmyk_conversion.py)
170174
* [Rgb Hsv Conversion](conversions/rgb_hsv_conversion.py)
171175
* [Roman Numerals](conversions/roman_numerals.py)
@@ -210,6 +214,7 @@
210214
* [Lazy Segment Tree](data_structures/binary_tree/lazy_segment_tree.py)
211215
* [Lowest Common Ancestor](data_structures/binary_tree/lowest_common_ancestor.py)
212216
* [Maximum Fenwick Tree](data_structures/binary_tree/maximum_fenwick_tree.py)
217+
* [Maximum Sum Bst](data_structures/binary_tree/maximum_sum_bst.py)
213218
* [Merge Two Binary Trees](data_structures/binary_tree/merge_two_binary_trees.py)
214219
* [Mirror Binary Tree](data_structures/binary_tree/mirror_binary_tree.py)
215220
* [Non Recursive Segment Tree](data_structures/binary_tree/non_recursive_segment_tree.py)
@@ -283,6 +288,7 @@
283288
* [Dijkstras Two Stack Algorithm](data_structures/stacks/dijkstras_two_stack_algorithm.py)
284289
* [Infix To Postfix Conversion](data_structures/stacks/infix_to_postfix_conversion.py)
285290
* [Infix To Prefix Conversion](data_structures/stacks/infix_to_prefix_conversion.py)
291+
* [Lexicographical Numbers](data_structures/stacks/lexicographical_numbers.py)
286292
* [Next Greater Element](data_structures/stacks/next_greater_element.py)
287293
* [Postfix Evaluation](data_structures/stacks/postfix_evaluation.py)
288294
* [Prefix Evaluation](data_structures/stacks/prefix_evaluation.py)
@@ -346,6 +352,9 @@
346352
* [Power](divide_and_conquer/power.py)
347353
* [Strassen Matrix Multiplication](divide_and_conquer/strassen_matrix_multiplication.py)
348354

355+
## Docs
356+
* [Conf](docs/conf.py)
357+
349358
## Dynamic Programming
350359
* [Abbreviation](dynamic_programming/abbreviation.py)
351360
* [All Construct](dynamic_programming/all_construct.py)
@@ -786,6 +795,7 @@
786795
* [Cramers Rule 2X2](matrix/cramers_rule_2x2.py)
787796
* [Inverse Of Matrix](matrix/inverse_of_matrix.py)
788797
* [Largest Square Area In Matrix](matrix/largest_square_area_in_matrix.py)
798+
* [Matrix Based Game](matrix/matrix_based_game.py)
789799
* [Matrix Class](matrix/matrix_class.py)
790800
* [Matrix Equalization](matrix/matrix_equalization.py)
791801
* [Matrix Multiplication Recursion](matrix/matrix_multiplication_recursion.py)
@@ -1200,6 +1210,7 @@
12001210
* [Binary Tree Traversal](searches/binary_tree_traversal.py)
12011211
* [Double Linear Search](searches/double_linear_search.py)
12021212
* [Double Linear Search Recursion](searches/double_linear_search_recursion.py)
1213+
* [Exponential Search](searches/exponential_search.py)
12031214
* [Fibonacci Search](searches/fibonacci_search.py)
12041215
* [Hill Climbing](searches/hill_climbing.py)
12051216
* [Interpolation Search](searches/interpolation_search.py)

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MIT License
1+
## MIT License
22

33
Copyright (c) 2016-2022 TheAlgorithms and contributors
44

audio_filters/iir_filter.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ class IIRFilter:
1010
1111
Implementation details:
1212
Based on the 2nd-order function from
13-
https://en.wikipedia.org/wiki/Digital_biquad_filter,
13+
https://en.wikipedia.org/wiki/Digital_biquad_filter,
1414
this generalized N-order function was made.
1515
1616
Using the following transfer function
17-
H(z)=\frac{b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+...+b_{k}z^{-k}}{a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+...+a_{k}z^{-k}}
17+
.. math:: H(z)=\frac{b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+...+b_{k}z^{-k}}
18+
{a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+...+a_{k}z^{-k}}
19+
1820
we can rewrite this to
19-
y[n]={\frac{1}{a_{0}}}\left(\left(b_{0}x[n]+b_{1}x[n-1]+b_{2}x[n-2]+...+b_{k}x[n-k]\right)-\left(a_{1}y[n-1]+a_{2}y[n-2]+...+a_{k}y[n-k]\right)\right)
21+
.. math:: y[n]={\frac{1}{a_{0}}}
22+
\left(\left(b_{0}x[n]+b_{1}x[n-1]+b_{2}x[n-2]+...+b_{k}x[n-k]\right)-
23+
\left(a_{1}y[n-1]+a_{2}y[n-2]+...+a_{k}y[n-k]\right)\right)
2024
"""
2125

2226
def __init__(self, order: int) -> None:
@@ -34,17 +38,19 @@ def __init__(self, order: int) -> None:
3438

3539
def set_coefficients(self, a_coeffs: list[float], b_coeffs: list[float]) -> None:
3640
"""
37-
Set the coefficients for the IIR filter. These should both be of size order + 1.
38-
a_0 may be left out, and it will use 1.0 as default value.
41+
Set the coefficients for the IIR filter.
42+
These should both be of size `order` + 1.
43+
:math:`a_0` may be left out, and it will use 1.0 as default value.
3944
4045
This method works well with scipy's filter design functions
41-
>>> # Make a 2nd-order 1000Hz butterworth lowpass filter
42-
>>> import scipy.signal
43-
>>> b_coeffs, a_coeffs = scipy.signal.butter(2, 1000,
44-
... btype='lowpass',
45-
... fs=48000)
46-
>>> filt = IIRFilter(2)
47-
>>> filt.set_coefficients(a_coeffs, b_coeffs)
46+
47+
>>> # Make a 2nd-order 1000Hz butterworth lowpass filter
48+
>>> import scipy.signal
49+
>>> b_coeffs, a_coeffs = scipy.signal.butter(2, 1000,
50+
... btype='lowpass',
51+
... fs=48000)
52+
>>> filt = IIRFilter(2)
53+
>>> filt.set_coefficients(a_coeffs, b_coeffs)
4854
"""
4955
if len(a_coeffs) < self.order:
5056
a_coeffs = [1.0, *a_coeffs]
@@ -68,7 +74,7 @@ def set_coefficients(self, a_coeffs: list[float], b_coeffs: list[float]) -> None
6874

6975
def process(self, sample: float) -> float:
7076
"""
71-
Calculate y[n]
77+
Calculate :math:`y[n]`
7278
7379
>>> filt = IIRFilter(2)
7480
>>> filt.process(0)

0 commit comments

Comments
 (0)