Skip to content

Commit 37a6a11

Browse files
authored
Merge branch 'TheAlgorithms:master' into master
2 parents 713d680 + 2d8f22a commit 37a6a11

File tree

828 files changed

+26807
-7355
lines changed

Some content is hidden

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

828 files changed

+26807
-7355
lines changed

.devcontainer/Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# https://github.com/microsoft/vscode-dev-containers/blob/main/containers/python-3/README.md
2+
ARG VARIANT=3.12-bookworm
3+
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}
4+
COPY requirements.txt /tmp/pip-tmp/
5+
RUN python3 -m pip install --upgrade pip \
6+
&& python3 -m pip install --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
7+
&& pipx install pre-commit ruff \
8+
&& pre-commit install

.devcontainer/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://code.visualstudio.com/docs/devcontainers/tutorial

.devcontainer/devcontainer.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "Python 3",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"context": "..",
6+
"args": {
7+
// Update 'VARIANT' to pick a Python version: 3, 3.11, 3.10, 3.9, 3.8
8+
// Append -bullseye or -buster to pin to an OS version.
9+
// Use -bullseye variants on local on arm64/Apple Silicon.
10+
"VARIANT": "3.12-bookworm",
11+
}
12+
},
13+
14+
// Configure tool-specific properties.
15+
"customizations": {
16+
// Configure properties specific to VS Code.
17+
"vscode": {
18+
// Set *default* container specific settings.json values on container create.
19+
"settings": {
20+
"python.defaultInterpreterPath": "/usr/local/bin/python",
21+
"python.linting.enabled": true,
22+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
23+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy"
24+
},
25+
26+
// Add the IDs of extensions you want installed when the container is created.
27+
"extensions": [
28+
"ms-python.python",
29+
"ms-python.vscode-pylance"
30+
]
31+
}
32+
},
33+
34+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
35+
// "forwardPorts": [],
36+
37+
// Use 'postCreateCommand' to run commands after the container is created.
38+
// "postCreateCommand": "pip3 install --user -r requirements.txt",
39+
40+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
41+
"remoteUser": "vscode"
42+
}

.github/CODEOWNERS

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Order is important. The last matching pattern has the most precedence.
99

10-
/.* @cclauss @dhruvmanila
10+
/.* @cclauss
1111

1212
# /arithmetic_analysis/
1313

@@ -21,15 +21,15 @@
2121

2222
# /cellular_automata/
2323

24-
# /ciphers/ @cclauss # TODO: Uncomment this line after Hacktoberfest
24+
# /ciphers/
2525

2626
# /compression/
2727

2828
# /computer_vision/
2929

30-
# /conversions/ @cclauss # TODO: Uncomment this line after Hacktoberfest
30+
# /conversions/
3131

32-
# /data_structures/ @cclauss # TODO: Uncomment this line after Hacktoberfest
32+
# /data_structures/
3333

3434
# /digital_image_processing/
3535

@@ -67,9 +67,9 @@
6767

6868
# /neural_network/
6969

70-
# /other/ @cclauss # TODO: Uncomment this line after Hacktoberfest
70+
# /other/
7171

72-
/project_euler/ @dhruvmanila
72+
# /project_euler/
7373

7474
# /quantum/
7575

@@ -81,7 +81,7 @@
8181

8282
# /sorts/
8383

84-
# /strings/ @cclauss # TODO: Uncomment this line after Hacktoberfest
84+
# /strings/
8585

8686
# /traversals/
8787

.github/ISSUE_TEMPLATE/feature_request.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ body:
66
attributes:
77
value: >
88
Before requesting please search [existing issues](https://github.com/TheAlgorithms/Python/labels/enhancement).
9+
Do not create issues to implement new algorithms as these will be closed.
910
Usage questions such as "How do I...?" belong on the
1011
[Discord](https://discord.gg/c7MnfGFGa6) and will be closed.
1112
1213
- type: textarea
1314
attributes:
1415
label: "Feature description"
1516
description: >
16-
This could be new algorithms, data structures or improving any existing
17-
implementations.
17+
This could include new topics or improving any existing implementations.
1818
validations:
1919
required: true

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Keep GitHub Actions up to date with Dependabot...
2+
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
3+
version: 2
4+
updates:
5+
- package-ecosystem: "github-actions"
6+
directory: "/"
7+
schedule:
8+
interval: "daily"

.github/pull_request_template.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* [ ] Add an algorithm?
66
* [ ] Fix a bug or typo in an existing algorithm?
7+
* [ ] Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
78
* [ ] Documentation change?
89

910
### Checklist:

.github/workflows/build.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
13-
- uses: actions/setup-python@v4
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
1414
with:
15-
python-version: 3.11
16-
- uses: actions/cache@v3
15+
python-version: 3.12
16+
allow-prereleases: true
17+
- uses: actions/cache@v4
1718
with:
1819
path: ~/.cache/pip
1920
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
@@ -24,10 +25,10 @@ jobs:
2425
- name: Run tests
2526
# TODO: #8818 Re-enable quantum tests
2627
run: pytest
27-
--ignore=quantum/q_fourier_transform.py
28-
--ignore=project_euler/
29-
--ignore=scripts/validate_solutions.py
30-
--cov-report=term-missing:skip-covered
31-
--cov=. .
28+
--ignore=quantum/q_fourier_transform.py
29+
--ignore=project_euler/
30+
--ignore=scripts/validate_solutions.py
31+
--cov-report=term-missing:skip-covered
32+
--cov=. .
3233
- if: ${{ success() }}
3334
run: scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md

.github/workflows/directory_writer.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ jobs:
66
build:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v1 # v1, NOT v2 or v3
10-
- uses: actions/setup-python@v4
9+
- uses: actions/checkout@v4
10+
with:
11+
fetch-depth: 0
12+
- uses: actions/setup-python@v5
1113
with:
1214
python-version: 3.x
1315
- name: Write DIRECTORY.md
1416
run: |
1517
scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md
16-
git config --global user.name github-actions
17-
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
18+
git config --global user.name "$GITHUB_ACTOR"
19+
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
1820
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
1921
- name: Update DIRECTORY.md
2022
run: |

.github/workflows/project_euler.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ jobs:
1414
project-euler:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
18-
- uses: actions/setup-python@v4
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v5
1919
with:
2020
python-version: 3.x
2121
- name: Install pytest and pytest-cov
2222
run: |
2323
python -m pip install --upgrade pip
24-
python -m pip install --upgrade pytest pytest-cov
24+
python -m pip install --upgrade numpy pytest pytest-cov
2525
- run: pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
2626
validate-solutions:
2727
runs-on: ubuntu-latest
2828
steps:
29-
- uses: actions/checkout@v3
30-
- uses: actions/setup-python@v4
29+
- uses: actions/checkout@v4
30+
- uses: actions/setup-python@v5
3131
with:
3232
python-version: 3.x
3333
- name: Install pytest and requests
3434
run: |
3535
python -m pip install --upgrade pip
36-
python -m pip install --upgrade pytest requests
36+
python -m pip install --upgrade numpy pytest requests
3737
- run: pytest scripts/validate_solutions.py
3838
env:
3939
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ruff.yml

+3-3
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@v3
15-
- run: pip install --user ruff
16-
- run: ruff --format=github .
14+
- uses: actions/checkout@v4
15+
- run: pip install --user ruff
16+
- run: ruff check --output-format=github .

.pre-commit-config.yaml

+16-13
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.4.0
3+
rev: v4.6.0
44
hooks:
55
- id: check-executables-have-shebangs
66
- id: check-toml
@@ -11,29 +11,25 @@ repos:
1111
- id: requirements-txt-fixer
1212

1313
- repo: https://github.com/MarcoGorelli/auto-walrus
14-
rev: v0.2.2
14+
rev: 0.3.4
1515
hooks:
16-
- id: auto-walrus
16+
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.0.277
19+
rev: v0.5.2
2020
hooks:
2121
- id: ruff
22-
23-
- repo: https://github.com/psf/black
24-
rev: 23.3.0
25-
hooks:
26-
- id: black
22+
- id: ruff-format
2723

2824
- repo: https://github.com/codespell-project/codespell
29-
rev: v2.2.5
25+
rev: v2.3.0
3026
hooks:
3127
- id: codespell
3228
additional_dependencies:
3329
- tomli
3430

3531
- repo: https://github.com/tox-dev/pyproject-fmt
36-
rev: "0.13.0"
32+
rev: "2.1.4"
3733
hooks:
3834
- id: pyproject-fmt
3935

@@ -46,16 +42,23 @@ repos:
4642
pass_filenames: false
4743

4844
- repo: https://github.com/abravalheri/validate-pyproject
49-
rev: v0.13
45+
rev: v0.18
5046
hooks:
5147
- id: validate-pyproject
5248

5349
- repo: https://github.com/pre-commit/mirrors-mypy
54-
rev: v1.4.1
50+
rev: v1.10.1
5551
hooks:
5652
- id: mypy
5753
args:
54+
- --explicit-package-bases
5855
- --ignore-missing-imports
5956
- --install-types # See mirrors-mypy README.md
6057
- --non-interactive
6158
additional_dependencies: [types-requests]
59+
60+
- repo: https://github.com/pre-commit/mirrors-prettier
61+
rev: "v4.0.0-alpha.8"
62+
hooks:
63+
- id: prettier
64+
types_or: [toml, yaml]

CONTRIBUTING.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,34 @@
22

33
## Before contributing
44

5-
Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before sending your pull requests, make sure that you __read the whole guidelines__. If you have any doubt on the contributing guide, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/Python/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms/community).
5+
Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before submitting your pull requests, please ensure that you __read the whole guidelines__. If you have any doubts about the contributing guide, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/Python/issues/new) or ask the community on [Gitter](https://gitter.im/TheAlgorithms/community).
66

77
## Contributing
88

99
### Contributor
1010

11-
We are very happy that you are considering implementing algorithms and data structures for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that:
11+
We are delighted that you are considering implementing algorithms and data structures for others! This repository is referenced and used by learners from all over the globe. By being one of our contributors, you agree and confirm that:
1212

13-
- You did your work - no plagiarism allowed
13+
- You did your work - no plagiarism allowed.
1414
- Any plagiarized work will not be merged.
15-
- Your work will be distributed under [MIT License](LICENSE.md) once your pull request is merged
16-
- Your submitted work fulfils or mostly fulfils our styles and standards
15+
- Your work will be distributed under [MIT License](LICENSE.md) once your pull request is merged.
16+
- Your submitted work fulfills or mostly fulfills our styles and standards.
1717

18-
__New implementation__ is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity but __identical implementation__ of an existing implementation is not allowed. Please check whether the solution is already implemented or not before submitting your pull request.
18+
__New implementation__ is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity, but __identical implementation__ of an existing implementation is not allowed. Please check whether the solution is already implemented or not before submitting your pull request.
1919

2020
__Improving comments__ and __writing proper tests__ are also highly welcome.
2121

2222
### Contribution
2323

2424
We appreciate any contribution, from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work.
2525

26-
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.
26+
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 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.
27+
28+
#### Issues
29+
30+
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.
31+
32+
__Do not__ create an issue to contribute an algorithm. Please submit a pull request instead.
2733

2834
Please help us keep our issue list small by adding `Fixes #{$ISSUE_NUMBER}` to the description of pull requests that resolve open issues.
2935
For example, if your pull request fixes issue #10, then please add the following to its description:
@@ -52,7 +58,7 @@ Algorithms should:
5258
* contain doctests that test both valid and erroneous input values
5359
* return all calculation results instead of printing or plotting them
5460

55-
Algorithms in this repo should not be how-to examples for existing Python packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values. Those calculations or manipulations can use data types, classes, or functions of existing Python packages but each algorithm in this repo should add unique value.
61+
Algorithms in this repo should not be how-to examples for existing Python packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values. Those calculations or manipulations can use data types, classes, or functions of existing Python packages but each algorithm in this repo should add unique value.
5662

5763
#### Pre-commit plugin
5864
Use [pre-commit](https://pre-commit.com/#installation) to automatically format your code to match our coding style:
@@ -71,7 +77,7 @@ pre-commit run --all-files --show-diff-on-failure
7177

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

74-
- Please write in Python 3.11+. 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.12+. For instance: `print()` is a function in Python 3 so `print "Hello"` will *not* work but `print("Hello")` will.
7581
- 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.
7682
- Single letter variable names are *old school* so please avoid them unless their life only spans a few lines.
7783
- Expand acronyms because `gcd()` is hard to understand but `greatest_common_divisor()` is not.
@@ -139,7 +145,7 @@ We want your work to be readable by others; therefore, we encourage you to note
139145
python3 -m doctest -v my_submission.py
140146
```
141147

142-
The use of the Python builtin `input()` function is __not__ encouraged:
148+
The use of the Python built-in `input()` function is __not__ encouraged:
143149

144150
```python
145151
input('Enter your input:')

0 commit comments

Comments
 (0)