Skip to content

Commit 19c3897

Browse files
Merge branch 'TheAlgorithms:master' into master
2 parents 581ca58 + 86b2ab0 commit 19c3897

40 files changed

+217
-167
lines changed

Diff for: .flake8

-10
This file was deleted.

Diff for: .github/stale.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pulls:
4545
closeComment: >
4646
Please reopen this pull request once you commit the changes requested
4747
or make improvements on the code. If this is not the case and you need
48-
some help, feel free to seek help from our [Gitter](https://gitter.im/TheAlgorithms)
48+
some help, feel free to seek help from our [Gitter](https://gitter.im/TheAlgorithms/community)
4949
or ping one of the reviewers. Thank you for your contributions!
5050
5151
issues:
@@ -59,5 +59,5 @@ issues:
5959
closeComment: >
6060
Please reopen this issue once you add more information and updates here.
6161
If this is not the case and you need some help, feel free to seek help
62-
from our [Gitter](https://gitter.im/TheAlgorithms) or ping one of the
62+
from our [Gitter](https://gitter.im/TheAlgorithms/community) or ping one of the
6363
reviewers. Thank you for your contributions!

Diff for: .github/workflows/ruff.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# https://beta.ruff.rs
2+
name: ruff
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
jobs:
11+
ruff:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- run: pip install --user ruff
16+
- run: ruff --format=github .

Diff for: .pre-commit-config.yaml

+19-59
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ repos:
33
rev: v4.4.0
44
hooks:
55
- id: check-executables-have-shebangs
6+
- id: check-toml
67
- id: check-yaml
78
- id: end-of-file-fixer
89
types: [python]
@@ -14,60 +15,41 @@ repos:
1415
hooks:
1516
- id: auto-walrus
1617

18+
- repo: https://github.com/charliermarsh/ruff-pre-commit
19+
rev: v0.0.259
20+
hooks:
21+
- id: ruff
22+
1723
- repo: https://github.com/psf/black
1824
rev: 23.1.0
1925
hooks:
2026
- id: black
2127

22-
- repo: https://github.com/PyCQA/isort
23-
rev: 5.12.0
28+
- repo: https://github.com/codespell-project/codespell
29+
rev: v2.2.4
2430
hooks:
25-
- id: isort
26-
args:
27-
- --profile=black
31+
- id: codespell
32+
additional_dependencies:
33+
- tomli
2834

2935
- repo: https://github.com/tox-dev/pyproject-fmt
3036
rev: "0.9.2"
3137
hooks:
3238
- id: pyproject-fmt
3339

40+
- repo: local
41+
hooks:
42+
- id: validate-filenames
43+
name: Validate filenames
44+
entry: ./scripts/validate_filenames.py
45+
language: script
46+
pass_filenames: false
47+
3448
- repo: https://github.com/abravalheri/validate-pyproject
3549
rev: v0.12.1
3650
hooks:
3751
- id: validate-pyproject
3852

39-
- repo: https://github.com/asottile/pyupgrade
40-
rev: v3.3.1
41-
hooks:
42-
- id: pyupgrade
43-
args:
44-
- --py311-plus
45-
46-
- repo: https://github.com/charliermarsh/ruff-pre-commit
47-
rev: v0.0.255
48-
hooks:
49-
- id: ruff
50-
args:
51-
- --ignore=E741
52-
53-
- repo: https://github.com/PyCQA/flake8
54-
rev: 6.0.0
55-
hooks:
56-
- id: flake8 # See .flake8 for args
57-
additional_dependencies: &flake8-plugins
58-
- flake8-bugbear
59-
- flake8-builtins
60-
# - flake8-broken-line
61-
- flake8-comprehensions
62-
- pep8-naming
63-
64-
- repo: https://github.com/asottile/yesqa
65-
rev: v1.4.0
66-
hooks:
67-
- id: yesqa
68-
additional_dependencies:
69-
*flake8-plugins
70-
7153
- repo: https://github.com/pre-commit/mirrors-mypy
7254
rev: v1.1.1
7355
hooks:
@@ -77,25 +59,3 @@ repos:
7759
- --install-types # See mirrors-mypy README.md
7860
- --non-interactive
7961
additional_dependencies: [types-requests]
80-
81-
- repo: https://github.com/codespell-project/codespell
82-
rev: v2.2.4
83-
hooks:
84-
- id: codespell
85-
args:
86-
- --ignore-words-list=3rt,ans,crate,damon,fo,followings,hist,iff,kwanza,mater,secant,som,sur,tim,zar
87-
exclude: |
88-
(?x)^(
89-
ciphers/prehistoric_men.txt |
90-
strings/dictionary.txt |
91-
strings/words.txt |
92-
project_euler/problem_022/p022_names.txt
93-
)$
94-
95-
- repo: local
96-
hooks:
97-
- id: validate-filenames
98-
name: Validate filenames
99-
entry: ./scripts/validate_filenames.py
100-
language: script
101-
pass_filenames: false

Diff for: CONTRIBUTING.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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).
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).
66

77
## Contributing
88

@@ -81,11 +81,11 @@ We want your work to be readable by others; therefore, we encourage you to note
8181
black .
8282
```
8383

84-
- All submissions will need to pass the test `flake8 . --ignore=E203,W503 --max-line-length=88` before they will be accepted so if possible, try this test locally on your Python file(s) before submitting your pull request.
84+
- All submissions will need to pass the test `ruff .` before they will be accepted so if possible, try this test locally on your Python file(s) before submitting your pull request.
8585

8686
```bash
87-
python3 -m pip install flake8 # only required the first time
88-
flake8 . --ignore=E203,W503 --max-line-length=88 --show-source
87+
python3 -m pip install ruff # only required the first time
88+
ruff .
8989
```
9090

9191
- Original code submission require docstrings or comments to describe your work.
@@ -176,7 +176,7 @@ We want your work to be readable by others; therefore, we encourage you to note
176176

177177
- Most importantly,
178178
- __Be consistent in the use of these guidelines when submitting.__
179-
- __Join__ us on [Discord](https://discord.com/invite/c7MnfGFGa6) and [Gitter](https://gitter.im/TheAlgorithms) __now!__
179+
- __Join__ us on [Discord](https://discord.com/invite/c7MnfGFGa6) and [Gitter](https://gitter.im/TheAlgorithms/community) __now!__
180180
- Happy coding!
181181

182182
Writer [@poyea](https://github.com/poyea), Jun 2019.

Diff for: DIRECTORY.md

+2
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@
976976
* [Sol1](project_euler/problem_125/sol1.py)
977977
* Problem 129
978978
* [Sol1](project_euler/problem_129/sol1.py)
979+
* Problem 131
980+
* [Sol1](project_euler/problem_131/sol1.py)
979981
* Problem 135
980982
* [Sol1](project_euler/problem_135/sol1.py)
981983
* Problem 144

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<a href="https://discord.gg/c7MnfGFGa6">
1717
<img src="https://img.shields.io/discord/808045925556682782.svg?logo=discord&colorB=7289DA&style=flat-square" height="20" alt="Discord chat">
1818
</a>
19-
<a href="https://gitter.im/TheAlgorithms">
19+
<a href="https://gitter.im/TheAlgorithms/community">
2020
<img src="https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square" height="20" alt="Gitter chat">
2121
</a>
2222
<!-- Second row: -->
@@ -42,7 +42,7 @@ Read through our [Contribution Guidelines](CONTRIBUTING.md) before you contribut
4242

4343
## Community Channels
4444

45-
We are on [Discord](https://discord.gg/c7MnfGFGa6) and [Gitter](https://gitter.im/TheAlgorithms)! Community channels are a great way for you to ask questions and get help. Please join us!
45+
We are on [Discord](https://discord.gg/c7MnfGFGa6) and [Gitter](https://gitter.im/TheAlgorithms/community)! Community channels are a great way for you to ask questions and get help. Please join us!
4646

4747
## List of Algorithms
4848

Diff for: arithmetic_analysis/newton_raphson.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import annotations
66

77
from decimal import Decimal
8-
from math import * # noqa: F401, F403
8+
from math import * # noqa: F403
99

1010
from sympy import diff
1111

Diff for: arithmetic_analysis/newton_raphson_new.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Newton's Method - https://en.wikipedia.org/wiki/Newton's_method
99

1010
from sympy import diff, lambdify, symbols
11-
from sympy.functions import * # noqa: F401, F403
11+
from sympy.functions import * # noqa: F403
1212

1313

1414
def newton_raphson(

Diff for: audio_filters/equal_loudness_filter.py.broken.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EqualLoudnessFilter:
2020
samplerate, use with caution.
2121

2222
Code based on matlab implementation at https://bit.ly/3eqh2HU
23-
(url shortened for flake8)
23+
(url shortened for ruff)
2424

2525
Target curve: https://i.imgur.com/3g2VfaM.png
2626
Yulewalk response: https://i.imgur.com/J9LnJ4C.png

Diff for: data_structures/binary_tree/avl_tree.py

-4
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,15 @@ def get_height(self) -> int:
6060

6161
def set_data(self, data: Any) -> None:
6262
self.data = data
63-
return
6463

6564
def set_left(self, node: MyNode | None) -> None:
6665
self.left = node
67-
return
6866

6967
def set_right(self, node: MyNode | None) -> None:
7068
self.right = node
71-
return
7269

7370
def set_height(self, height: int) -> None:
7471
self.height = height
75-
return
7672

7773

7874
def get_height(node: MyNode | None) -> int:

Diff for: data_structures/binary_tree/red_black_tree.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
python/black : true
3-
flake8 : passed
2+
psf/black : true
3+
ruff : passed
44
"""
55
from __future__ import annotations
66

Diff for: data_structures/heap/heap_generic.py

-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ def test_heap() -> None:
166166
>>> h.get_top()
167167
[9, -40]
168168
"""
169-
pass
170169

171170

172171
if __name__ == "__main__":

Diff for: digital_image_processing/change_contrast.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
This algorithm is used in
55
https://noivce.pythonanywhere.com/ Python web app.
66
7-
python/black: True
8-
flake8 : True
7+
psf/black: True
8+
ruff : True
99
"""
1010

1111
from PIL import Image

Diff for: dynamic_programming/min_distance_up_bottom.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
The aim is to demonstate up bottom approach for solving the task.
77
The implementation was tested on the
88
leetcode: https://leetcode.com/problems/edit-distance/
9-
"""
109
11-
"""
1210
Levinstein distance
1311
Dynamic Programming: up -> down.
1412
"""
1513

14+
import functools
15+
1616

1717
def min_distance_up_bottom(word1: str, word2: str) -> int:
1818
"""
@@ -25,13 +25,10 @@ def min_distance_up_bottom(word1: str, word2: str) -> int:
2525
>>> min_distance_up_bottom("zooicoarchaeologist", "zoologist")
2626
10
2727
"""
28-
29-
from functools import lru_cache
30-
3128
len_word1 = len(word1)
3229
len_word2 = len(word2)
3330

34-
@lru_cache(maxsize=None)
31+
@functools.cache
3532
def min_distance(index1: int, index2: int) -> int:
3633
# if first word index is overflow - delete all from the second word
3734
if index1 >= len_word1:

Diff for: dynamic_programming/minimum_tickets_cost.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
Dynamic Programming: up -> down.
2323
"""
2424

25-
from functools import lru_cache
25+
import functools
2626

2727

2828
def mincost_tickets(days: list[int], costs: list[int]) -> int:
@@ -106,7 +106,7 @@ def mincost_tickets(days: list[int], costs: list[int]) -> int:
106106

107107
days_set = set(days)
108108

109-
@lru_cache(maxsize=None)
109+
@functools.cache
110110
def dynamic_programming(index: int) -> int:
111111
if index > 365:
112112
return 0

Diff for: dynamic_programming/word_break.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Space: O(n)
2121
"""
2222

23-
from functools import lru_cache
23+
import functools
2424
from typing import Any
2525

2626

@@ -80,7 +80,7 @@ def word_break(string: str, words: list[str]) -> bool:
8080
len_string = len(string)
8181

8282
# Dynamic programming method
83-
@lru_cache(maxsize=None)
83+
@functools.cache
8484
def is_breakable(index: int) -> bool:
8585
"""
8686
>>> string = 'a'

Diff for: hashes/sha1.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import argparse
2727
import hashlib # hashlib is only used inside the Test class
2828
import struct
29-
import unittest
3029

3130

3231
class SHA1Hash:
@@ -125,17 +124,12 @@ def final_hash(self):
125124
self.h[3] + d & 0xFFFFFFFF,
126125
self.h[4] + e & 0xFFFFFFFF,
127126
)
128-
return "%08x%08x%08x%08x%08x" % tuple(self.h)
127+
return ("{:08x}" * 5).format(*self.h)
129128

130129

131-
class SHA1HashTest(unittest.TestCase):
132-
"""
133-
Test class for the SHA1Hash class. Inherits the TestCase class from unittest
134-
"""
135-
136-
def testMatchHashes(self): # noqa: N802
137-
msg = bytes("Test String", "utf-8")
138-
self.assertEqual(SHA1Hash(msg).final_hash(), hashlib.sha1(msg).hexdigest())
130+
def test_sha1_hash():
131+
msg = b"Test String"
132+
assert SHA1Hash(msg).final_hash() == hashlib.sha1(msg).hexdigest() # noqa: S324
139133

140134

141135
def main():

Diff for: machine_learning/polymonial_regression.py

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def viz_polymonial():
3434
plt.xlabel("Position level")
3535
plt.ylabel("Salary")
3636
plt.show()
37-
return
3837

3938

4039
if __name__ == "__main__":

0 commit comments

Comments
 (0)