Skip to content

[pre-commit.ci] pre-commit autoupdate #11322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: auto-walrus

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.3.2
hooks:
- id: ruff
- id: ruff-format
Expand Down Expand Up @@ -47,7 +47,7 @@ repos:
- id: validate-pyproject

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.9.0
hooks:
- id: mypy
args:
Expand Down
7 changes: 4 additions & 3 deletions backtracking/all_combinations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
In this problem, we want to determine all possible combinations of k
numbers out of 1 ... n. We use backtracking to solve this problem.
In this problem, we want to determine all possible combinations of k
numbers out of 1 ... n. We use backtracking to solve this problem.

Time complexity: O(C(n,k)) which is O(n choose k) = O((n!/(k! * (n - k)!))),
Time complexity: O(C(n,k)) which is O(n choose k) = O((n!/(k! * (n - k)!))),
"""

from __future__ import annotations

from itertools import combinations
Expand Down
9 changes: 5 additions & 4 deletions backtracking/all_permutations.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
In this problem, we want to determine all possible permutations
of the given sequence. We use backtracking to solve this problem.
In this problem, we want to determine all possible permutations
of the given sequence. We use backtracking to solve this problem.

Time complexity: O(n! * n),
where n denotes the length of the given sequence.
Time complexity: O(n! * n),
where n denotes the length of the given sequence.
"""

from __future__ import annotations


Expand Down
1 change: 1 addition & 0 deletions backtracking/all_subsequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Time complexity: O(2^n),
where n denotes the length of the given sequence.
"""

from __future__ import annotations

from typing import Any
Expand Down
8 changes: 4 additions & 4 deletions backtracking/coloring.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Graph Coloring also called "m coloring problem"
consists of coloring a given graph with at most m colors
such that no adjacent vertices are assigned the same color
Graph Coloring also called "m coloring problem"
consists of coloring a given graph with at most m colors
such that no adjacent vertices are assigned the same color

Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring
Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring
"""


Expand Down
10 changes: 5 additions & 5 deletions backtracking/hamiltonian_cycle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
A Hamiltonian cycle (Hamiltonian circuit) is a graph cycle
through a graph that visits each node exactly once.
Determining whether such paths and cycles exist in graphs
is the 'Hamiltonian path problem', which is NP-complete.
A Hamiltonian cycle (Hamiltonian circuit) is a graph cycle
through a graph that visits each node exactly once.
Determining whether such paths and cycles exist in graphs
is the 'Hamiltonian path problem', which is NP-complete.

Wikipedia: https://en.wikipedia.org/wiki/Hamiltonian_path
Wikipedia: https://en.wikipedia.org/wiki/Hamiltonian_path
"""


Expand Down
1 change: 1 addition & 0 deletions backtracking/minimax.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
leaves of game tree is stored in scores[]
height is maximum height of Game tree
"""

from __future__ import annotations

import math
Expand Down
11 changes: 6 additions & 5 deletions backtracking/n_queens.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""

The nqueens problem is of placing N queens on a N * N
chess board such that no queen can attack any other queens placed
on that chess board.
This means that one queen cannot have any other queen on its horizontal, vertical and
diagonal lines.
The nqueens problem is of placing N queens on a N * N
chess board such that no queen can attack any other queens placed
on that chess board.
This means that one queen cannot have any other queen on its horizontal, vertical and
diagonal lines.

"""

from __future__ import annotations

solution = []
Expand Down
1 change: 1 addition & 0 deletions backtracking/n_queens_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
for another one or vice versa.

"""

from __future__ import annotations


Expand Down
1 change: 1 addition & 0 deletions backtracking/sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
have solved the puzzle. else, we backtrack and place another number
in that cell and repeat this process.
"""

from __future__ import annotations

Matrix = list[list[int]]
Expand Down
11 changes: 6 additions & 5 deletions backtracking/sum_of_subsets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""
The sum-of-subsetsproblem states that a set of non-negative integers, and a
value M, determine all possible subsets of the given set whose summation sum
equal to given M.
The sum-of-subsetsproblem states that a set of non-negative integers, and a
value M, determine all possible subsets of the given set whose summation sum
equal to given M.

Summation of the chosen numbers must be equal to given number M and one number
can be used only once.
Summation of the chosen numbers must be equal to given number M and one number
can be used only once.
"""

from __future__ import annotations


Expand Down
1 change: 1 addition & 0 deletions boolean_algebra/nor_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Code provided by Akshaj Vishwanathan
https://www.geeksforgeeks.org/logic-gates-in-python
"""

from collections.abc import Callable


Expand Down
1 change: 1 addition & 0 deletions cellular_automata/conways_game_of_life.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Conway's Game of Life implemented in Python.
https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
"""

from __future__ import annotations

from PIL import Image
Expand Down
3 changes: 2 additions & 1 deletion cellular_automata/game_of_life.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
4.
Any dead cell with exactly three live neighbours be-
comes a live cell, as if by reproduction.
"""
"""

import random
import sys

Expand Down
1 change: 1 addition & 0 deletions cellular_automata/nagel_schrekenberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
>>> simulate(construct_highway(5, 2, -2), 3, 0, 2)
[[0, -1, 0, -1, 0], [0, -1, 0, -1, -1], [0, -1, -1, 1, -1], [-1, 1, -1, 0, -1]]
"""

from random import randint, random


Expand Down
1 change: 1 addition & 0 deletions ciphers/a1z26.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
https://www.dcode.fr/letter-number-cipher
http://bestcodes.weebly.com/a1z26.html
"""

from __future__ import annotations


Expand Down
3 changes: 2 additions & 1 deletion ciphers/atbash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" https://en.wikipedia.org/wiki/Atbash """
"""https://en.wikipedia.org/wiki/Atbash"""

import string


Expand Down
1 change: 1 addition & 0 deletions ciphers/base32.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

https://en.wikipedia.org/wiki/Base32
"""

B32_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"


Expand Down
1 change: 1 addition & 0 deletions ciphers/enigma_machine2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

Created by TrapinchO
"""

from __future__ import annotations

RotorPositionT = tuple[int, int, int]
Expand Down
1 change: 1 addition & 0 deletions ciphers/fractionated_morse_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

http://practicalcryptography.com/ciphers/fractionated-morse-cipher/
"""

import string

MORSE_CODE_DICT = {
Expand Down
1 change: 1 addition & 0 deletions ciphers/hill_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
https://www.youtube.com/watch?v=4RhLNDqcjpA

"""

import string

import numpy
Expand Down
1 change: 1 addition & 0 deletions ciphers/permutation_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

For more info: https://www.nku.edu/~christensen/1402%20permutation%20ciphers.pdf
"""

import random


Expand Down
2 changes: 1 addition & 1 deletion ciphers/rail_fence_cipher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" https://en.wikipedia.org/wiki/Rail_fence_cipher """
"""https://en.wikipedia.org/wiki/Rail_fence_cipher"""


def encrypt(input_string: str, key: int) -> str:
Expand Down
1 change: 1 addition & 0 deletions ciphers/rsa_factorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
More readable source: https://www.di-mgt.com.au/rsa_factorize_n.html
large number can take minutes to factor, therefore are not included in doctest.
"""

from __future__ import annotations

import math
Expand Down
33 changes: 17 additions & 16 deletions ciphers/xor_cipher.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
"""
author: Christian Bender
date: 21.12.2017
class: XORCipher

This class implements the XOR-cipher algorithm and provides
some useful methods for encrypting and decrypting strings and
files.

Overview about methods

- encrypt : list of char
- decrypt : list of char
- encrypt_string : str
- decrypt_string : str
- encrypt_file : boolean
- decrypt_file : boolean
author: Christian Bender
date: 21.12.2017
class: XORCipher

This class implements the XOR-cipher algorithm and provides
some useful methods for encrypting and decrypting strings and
files.

Overview about methods

- encrypt : list of char
- decrypt : list of char
- encrypt_string : str
- decrypt_string : str
- encrypt_file : boolean
- decrypt_file : boolean
"""

from __future__ import annotations


Expand Down
1 change: 1 addition & 0 deletions compression/burrows_wheeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
original character. The BWT is thus a "free" method of improving the efficiency
of text compression algorithms, costing only some extra computation.
"""

from __future__ import annotations

from typing import TypedDict
Expand Down
4 changes: 2 additions & 2 deletions compression/lempel_ziv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
One of the several implementations of Lempel–Ziv–Welch compression algorithm
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
One of the several implementations of Lempel–Ziv–Welch compression algorithm
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
"""

import math
Expand Down
4 changes: 2 additions & 2 deletions compression/lempel_ziv_decompress.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
One of the several implementations of Lempel–Ziv–Welch decompression algorithm
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
One of the several implementations of Lempel–Ziv–Welch decompression algorithm
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
"""

import math
Expand Down
1 change: 0 additions & 1 deletion compression/lz77.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
en.wikipedia.org/wiki/LZ77_and_LZ78
"""


from dataclasses import dataclass

__version__ = "0.1"
Expand Down
1 change: 1 addition & 0 deletions computer_vision/haralick_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
https://en.wikipedia.org/wiki/Image_texture
https://en.wikipedia.org/wiki/Co-occurrence_matrix#Application_to_image_analysis
"""

import imageio.v2 as imageio
import numpy as np

Expand Down
16 changes: 8 additions & 8 deletions computer_vision/horn_schunck.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
The Horn-Schunck method estimates the optical flow for every single pixel of
a sequence of images.
It works by assuming brightness constancy between two consecutive frames
and smoothness in the optical flow.

Useful resources:
Wikipedia: https://en.wikipedia.org/wiki/Horn%E2%80%93Schunck_method
Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf
The Horn-Schunck method estimates the optical flow for every single pixel of
a sequence of images.
It works by assuming brightness constancy between two consecutive frames
and smoothness in the optical flow.

Useful resources:
Wikipedia: https://en.wikipedia.org/wiki/Horn%E2%80%93Schunck_method
Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf
"""

from typing import SupportsIndex
Expand Down
2 changes: 1 addition & 1 deletion conversions/decimal_to_hexadecimal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Convert Base 10 (Decimal) Values to Hexadecimal Representations """
"""Convert Base 10 (Decimal) Values to Hexadecimal Representations"""

# set decimal value for each hexadecimal digit
values = {
Expand Down
1 change: 1 addition & 0 deletions conversions/prefix_conversions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Convert International System of Units (SI) and Binary prefixes
"""

from __future__ import annotations

from enum import Enum
Expand Down
2 changes: 1 addition & 1 deletion conversions/temperature_conversions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Convert between different units of temperature """
"""Convert between different units of temperature"""


def celsius_to_fahrenheit(celsius: float, ndigits: int = 2) -> float:
Expand Down
1 change: 1 addition & 0 deletions data_structures/arrays/pairs_with_given_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

https://practice.geeksforgeeks.org/problems/count-pairs-with-given-sum5022/0
"""

from itertools import combinations


Expand Down
Loading