Skip to content

Commit bc8df6d

Browse files
[pre-commit.ci] pre-commit autoupdate (TheAlgorithms#11322)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](astral-sh/ruff-pre-commit@v0.2.2...v0.3.2) - [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](pre-commit/mirrors-mypy@v1.8.0...v1.9.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5f95d6f commit bc8df6d

File tree

297 files changed

+498
-295
lines changed

Some content is hidden

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

297 files changed

+498
-295
lines changed

.pre-commit-config.yaml

+2-2
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.2.2
19+
rev: v0.3.2
2020
hooks:
2121
- id: ruff
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.8.0
50+
rev: v1.9.0
5151
hooks:
5252
- id: mypy
5353
args:

backtracking/all_combinations.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""
2-
In this problem, we want to determine all possible combinations of k
3-
numbers out of 1 ... n. We use backtracking to solve this problem.
2+
In this problem, we want to determine all possible combinations of k
3+
numbers out of 1 ... n. We use backtracking to solve this problem.
44
5-
Time complexity: O(C(n,k)) which is O(n choose k) = O((n!/(k! * (n - k)!))),
5+
Time complexity: O(C(n,k)) which is O(n choose k) = O((n!/(k! * (n - k)!))),
66
"""
7+
78
from __future__ import annotations
89

910
from itertools import combinations

backtracking/all_permutations.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""
2-
In this problem, we want to determine all possible permutations
3-
of the given sequence. We use backtracking to solve this problem.
2+
In this problem, we want to determine all possible permutations
3+
of the given sequence. We use backtracking to solve this problem.
44
5-
Time complexity: O(n! * n),
6-
where n denotes the length of the given sequence.
5+
Time complexity: O(n! * n),
6+
where n denotes the length of the given sequence.
77
"""
8+
89
from __future__ import annotations
910

1011

backtracking/all_subsequences.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Time complexity: O(2^n),
66
where n denotes the length of the given sequence.
77
"""
8+
89
from __future__ import annotations
910

1011
from typing import Any

backtracking/coloring.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
2-
Graph Coloring also called "m coloring problem"
3-
consists of coloring a given graph with at most m colors
4-
such that no adjacent vertices are assigned the same color
2+
Graph Coloring also called "m coloring problem"
3+
consists of coloring a given graph with at most m colors
4+
such that no adjacent vertices are assigned the same color
55
6-
Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring
6+
Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring
77
"""
88

99

backtracking/hamiltonian_cycle.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
A Hamiltonian cycle (Hamiltonian circuit) is a graph cycle
3-
through a graph that visits each node exactly once.
4-
Determining whether such paths and cycles exist in graphs
5-
is the 'Hamiltonian path problem', which is NP-complete.
2+
A Hamiltonian cycle (Hamiltonian circuit) is a graph cycle
3+
through a graph that visits each node exactly once.
4+
Determining whether such paths and cycles exist in graphs
5+
is the 'Hamiltonian path problem', which is NP-complete.
66
7-
Wikipedia: https://en.wikipedia.org/wiki/Hamiltonian_path
7+
Wikipedia: https://en.wikipedia.org/wiki/Hamiltonian_path
88
"""
99

1010

backtracking/minimax.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
leaves of game tree is stored in scores[]
88
height is maximum height of Game tree
99
"""
10+
1011
from __future__ import annotations
1112

1213
import math

backtracking/n_queens.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
22
3-
The nqueens problem is of placing N queens on a N * N
4-
chess board such that no queen can attack any other queens placed
5-
on that chess board.
6-
This means that one queen cannot have any other queen on its horizontal, vertical and
7-
diagonal lines.
3+
The nqueens problem is of placing N queens on a N * N
4+
chess board such that no queen can attack any other queens placed
5+
on that chess board.
6+
This means that one queen cannot have any other queen on its horizontal, vertical and
7+
diagonal lines.
88
99
"""
10+
1011
from __future__ import annotations
1112

1213
solution = []

backtracking/n_queens_math.py

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
for another one or vice versa.
7676
7777
"""
78+
7879
from __future__ import annotations
7980

8081

backtracking/sudoku.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
have solved the puzzle. else, we backtrack and place another number
1010
in that cell and repeat this process.
1111
"""
12+
1213
from __future__ import annotations
1314

1415
Matrix = list[list[int]]

backtracking/sum_of_subsets.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""
2-
The sum-of-subsetsproblem states that a set of non-negative integers, and a
3-
value M, determine all possible subsets of the given set whose summation sum
4-
equal to given M.
2+
The sum-of-subsetsproblem states that a set of non-negative integers, and a
3+
value M, determine all possible subsets of the given set whose summation sum
4+
equal to given M.
55
6-
Summation of the chosen numbers must be equal to given number M and one number
7-
can be used only once.
6+
Summation of the chosen numbers must be equal to given number M and one number
7+
can be used only once.
88
"""
9+
910
from __future__ import annotations
1011

1112

boolean_algebra/nor_gate.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Code provided by Akshaj Vishwanathan
1313
https://www.geeksforgeeks.org/logic-gates-in-python
1414
"""
15+
1516
from collections.abc import Callable
1617

1718

cellular_automata/conways_game_of_life.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Conway's Game of Life implemented in Python.
33
https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
44
"""
5+
56
from __future__ import annotations
67

78
from PIL import Image

cellular_automata/game_of_life.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
4.
2727
Any dead cell with exactly three live neighbours be-
2828
comes a live cell, as if by reproduction.
29-
"""
29+
"""
30+
3031
import random
3132
import sys
3233

cellular_automata/nagel_schrekenberg.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
>>> simulate(construct_highway(5, 2, -2), 3, 0, 2)
2525
[[0, -1, 0, -1, 0], [0, -1, 0, -1, -1], [0, -1, -1, 1, -1], [-1, 1, -1, 0, -1]]
2626
"""
27+
2728
from random import randint, random
2829

2930

ciphers/a1z26.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
https://www.dcode.fr/letter-number-cipher
66
http://bestcodes.weebly.com/a1z26.html
77
"""
8+
89
from __future__ import annotations
910

1011

ciphers/atbash.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
""" https://en.wikipedia.org/wiki/Atbash """
1+
"""https://en.wikipedia.org/wiki/Atbash"""
2+
23
import string
34

45

ciphers/base32.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
https://en.wikipedia.org/wiki/Base32
55
"""
6+
67
B32_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
78

89

ciphers/enigma_machine2.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
Created by TrapinchO
1616
"""
17+
1718
from __future__ import annotations
1819

1920
RotorPositionT = tuple[int, int, int]

ciphers/fractionated_morse_cipher.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
http://practicalcryptography.com/ciphers/fractionated-morse-cipher/
1010
"""
11+
1112
import string
1213

1314
MORSE_CODE_DICT = {

ciphers/hill_cipher.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
https://www.youtube.com/watch?v=4RhLNDqcjpA
3636
3737
"""
38+
3839
import string
3940

4041
import numpy

ciphers/permutation_cipher.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
For more info: https://www.nku.edu/~christensen/1402%20permutation%20ciphers.pdf
99
"""
10+
1011
import random
1112

1213

ciphers/rail_fence_cipher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" https://en.wikipedia.org/wiki/Rail_fence_cipher """
1+
"""https://en.wikipedia.org/wiki/Rail_fence_cipher"""
22

33

44
def encrypt(input_string: str, key: int) -> str:

ciphers/rsa_factorization.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
More readable source: https://www.di-mgt.com.au/rsa_factorize_n.html
88
large number can take minutes to factor, therefore are not included in doctest.
99
"""
10+
1011
from __future__ import annotations
1112

1213
import math

ciphers/xor_cipher.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
"""
2-
author: Christian Bender
3-
date: 21.12.2017
4-
class: XORCipher
5-
6-
This class implements the XOR-cipher algorithm and provides
7-
some useful methods for encrypting and decrypting strings and
8-
files.
9-
10-
Overview about methods
11-
12-
- encrypt : list of char
13-
- decrypt : list of char
14-
- encrypt_string : str
15-
- decrypt_string : str
16-
- encrypt_file : boolean
17-
- decrypt_file : boolean
2+
author: Christian Bender
3+
date: 21.12.2017
4+
class: XORCipher
5+
6+
This class implements the XOR-cipher algorithm and provides
7+
some useful methods for encrypting and decrypting strings and
8+
files.
9+
10+
Overview about methods
11+
12+
- encrypt : list of char
13+
- decrypt : list of char
14+
- encrypt_string : str
15+
- decrypt_string : str
16+
- encrypt_file : boolean
17+
- decrypt_file : boolean
1818
"""
19+
1920
from __future__ import annotations
2021

2122

compression/burrows_wheeler.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
original character. The BWT is thus a "free" method of improving the efficiency
1111
of text compression algorithms, costing only some extra computation.
1212
"""
13+
1314
from __future__ import annotations
1415

1516
from typing import TypedDict

compression/lempel_ziv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
One of the several implementations of Lempel–Ziv–Welch compression algorithm
3-
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
2+
One of the several implementations of Lempel–Ziv–Welch compression algorithm
3+
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
44
"""
55

66
import math

compression/lempel_ziv_decompress.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
One of the several implementations of Lempel–Ziv–Welch decompression algorithm
3-
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
2+
One of the several implementations of Lempel–Ziv–Welch decompression algorithm
3+
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
44
"""
55

66
import math

compression/lz77.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
en.wikipedia.org/wiki/LZ77_and_LZ78
2929
"""
3030

31-
3231
from dataclasses import dataclass
3332

3433
__version__ = "0.1"

computer_vision/haralick_descriptors.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
https://en.wikipedia.org/wiki/Image_texture
33
https://en.wikipedia.org/wiki/Co-occurrence_matrix#Application_to_image_analysis
44
"""
5+
56
import imageio.v2 as imageio
67
import numpy as np
78

computer_vision/horn_schunck.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
The Horn-Schunck method estimates the optical flow for every single pixel of
3-
a sequence of images.
4-
It works by assuming brightness constancy between two consecutive frames
5-
and smoothness in the optical flow.
6-
7-
Useful resources:
8-
Wikipedia: https://en.wikipedia.org/wiki/Horn%E2%80%93Schunck_method
9-
Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf
2+
The Horn-Schunck method estimates the optical flow for every single pixel of
3+
a sequence of images.
4+
It works by assuming brightness constancy between two consecutive frames
5+
and smoothness in the optical flow.
6+
7+
Useful resources:
8+
Wikipedia: https://en.wikipedia.org/wiki/Horn%E2%80%93Schunck_method
9+
Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf
1010
"""
1111

1212
from typing import SupportsIndex

conversions/decimal_to_hexadecimal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Convert Base 10 (Decimal) Values to Hexadecimal Representations """
1+
"""Convert Base 10 (Decimal) Values to Hexadecimal Representations"""
22

33
# set decimal value for each hexadecimal digit
44
values = {

conversions/prefix_conversions.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Convert International System of Units (SI) and Binary prefixes
33
"""
4+
45
from __future__ import annotations
56

67
from enum import Enum

conversions/temperature_conversions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Convert between different units of temperature """
1+
"""Convert between different units of temperature"""
22

33

44
def celsius_to_fahrenheit(celsius: float, ndigits: int = 2) -> float:

data_structures/arrays/pairs_with_given_sum.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
https://practice.geeksforgeeks.org/problems/count-pairs-with-given-sum5022/0
88
"""
9+
910
from itertools import combinations
1011

1112

0 commit comments

Comments
 (0)