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

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2)
- [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/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>
This commit is contained in:
pre-commit-ci[bot] 2024-03-13 07:52:41 +01:00 committed by GitHub
parent 5f95d6f805
commit bc8df6de31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
297 changed files with 488 additions and 285 deletions

View File

@ -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
@ -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:

View File

@ -4,6 +4,7 @@
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

View File

@ -5,6 +5,7 @@
Time complexity: O(n! * n),
where n denotes the length of the given sequence.
"""
from __future__ import annotations

View File

@ -5,6 +5,7 @@ of the given sequence. We use backtracking to solve this problem.
Time complexity: O(2^n),
where n denotes the length of the given sequence.
"""
from __future__ import annotations
from typing import Any

View File

@ -7,6 +7,7 @@ if move is of maximizer return true else false
leaves of game tree is stored in scores[]
height is maximum height of Game tree
"""
from __future__ import annotations
import math

View File

@ -7,6 +7,7 @@
diagonal lines.
"""
from __future__ import annotations
solution = []

View File

@ -75,6 +75,7 @@ Applying these two formulas we can check if a queen in some position is being at
for another one or vice versa.
"""
from __future__ import annotations

View File

@ -9,6 +9,7 @@ function on the next column to see if it returns True. if yes, we
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]]

View File

@ -6,6 +6,7 @@
Summation of the chosen numbers must be equal to given number M and one number
can be used only once.
"""
from __future__ import annotations

View File

@ -12,6 +12,7 @@ Following is the truth table of a NOR Gate:
Code provided by Akshaj Vishwanathan
https://www.geeksforgeeks.org/logic-gates-in-python
"""
from collections.abc import Callable

View File

@ -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

View File

@ -27,6 +27,7 @@ Game-Of-Life Rules:
Any dead cell with exactly three live neighbours be-
comes a live cell, as if by reproduction.
"""
import random
import sys

View File

@ -24,6 +24,7 @@ Examples for doctest:
>>> 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

View File

@ -5,6 +5,7 @@ corresponding to the character's position in the alphabet.
https://www.dcode.fr/letter-number-cipher
http://bestcodes.weebly.com/a1z26.html
"""
from __future__ import annotations

View File

@ -1,4 +1,5 @@
"""https://en.wikipedia.org/wiki/Atbash"""
import string

View File

@ -3,6 +3,7 @@ Base32 encoding and decoding
https://en.wikipedia.org/wiki/Base32
"""
B32_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"

View File

@ -14,6 +14,7 @@ Module includes:
Created by TrapinchO
"""
from __future__ import annotations
RotorPositionT = tuple[int, int, int]

View File

@ -8,6 +8,7 @@ making it more secure than substitution ciphers.
http://practicalcryptography.com/ciphers/fractionated-morse-cipher/
"""
import string
MORSE_CODE_DICT = {

View File

@ -35,6 +35,7 @@ https://www.youtube.com/watch?v=kfmNeskzs2o
https://www.youtube.com/watch?v=4RhLNDqcjpA
"""
import string
import numpy

View File

@ -7,6 +7,7 @@ determine the order of character rearrangement.
For more info: https://www.nku.edu/~christensen/1402%20permutation%20ciphers.pdf
"""
import random

View File

@ -7,6 +7,7 @@ Source: on page 3 of https://crypto.stanford.edu/~dabo/papers/RSA-survey.pdf
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

View File

@ -16,6 +16,7 @@
- encrypt_file : boolean
- decrypt_file : boolean
"""
from __future__ import annotations

View File

@ -10,6 +10,7 @@ without needing to store any additional data except the position of the first
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

View File

@ -28,7 +28,6 @@ Sources:
en.wikipedia.org/wiki/LZ77_and_LZ78
"""
from dataclasses import dataclass
__version__ = "0.1"

View File

@ -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

View File

@ -1,6 +1,7 @@
"""
Convert International System of Units (SI) and Binary prefixes
"""
from __future__ import annotations
from enum import Enum

View File

@ -6,6 +6,7 @@ elements whose sum is equal to req_sum.
https://practice.geeksforgeeks.org/problems/count-pairs-with-given-sum5022/0
"""
from itertools import combinations

View File

@ -10,6 +10,7 @@
Wikipedia link: https://en.wikipedia.org/wiki/Range_minimum_query
"""
from math import log2

View File

@ -3,6 +3,7 @@ Please do not modify this file! It is published at https://norvig.com/sudoku.ht
only minimal changes to work with modern versions of Python. If you have improvements,
please make them in a separate file.
"""
import random
import time

View File

@ -5,6 +5,7 @@ python3 -m doctest -v avl_tree.py
For testing run:
python avl_tree.py
"""
from __future__ import annotations
import math

View File

@ -88,6 +88,7 @@ True
>>> not t
True
"""
from __future__ import annotations
from collections.abc import Iterable, Iterator

View File

@ -7,6 +7,7 @@ python -m unittest binary_search_tree_recursive.py
To run an example:
python binary_search_tree_recursive.py
"""
from __future__ import annotations
import unittest

View File

@ -8,7 +8,6 @@ Python implementation:
frames that could be in memory is `n`
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -2,6 +2,7 @@
The diameter/width of a tree is defined as the number of nodes on the longest path
between two end nodes.
"""
from __future__ import annotations
from dataclasses import dataclass

View File

@ -10,6 +10,7 @@ https://www.geeksforgeeks.org/flatten-a-binary-tree-into-linked-list
Author: Arunkumar A
Date: 04/09/2023
"""
from __future__ import annotations

View File

@ -9,6 +9,7 @@ https://bit.ly/46uB0a2
Author : Arunkumar
Date : 14th October 2023
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -13,6 +13,7 @@ If n is the number of nodes in the tree then:
Runtime: O(n)
Space: O(1)
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -3,6 +3,7 @@ Is a binary tree a sum tree where the value of every non-leaf node is equal to t
of the values of its left and right subtrees?
https://www.geeksforgeeks.org/check-if-a-given-binary-tree-is-sumtree
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -5,6 +5,7 @@ The rule for merging is that if two nodes overlap, then put the value sum of
both nodes to the new value of the merged node. Otherwise, the NOT null node
will be used as the node of new tree.
"""
from __future__ import annotations

View File

@ -3,6 +3,7 @@ Given the root of a binary tree, mirror the tree, and return its root.
Leetcode problem reference: https://leetcode.com/problems/mirror-binary-tree/
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -35,6 +35,7 @@ https://www.geeksforgeeks.org/segment-tree-efficient-implementation/
>>> st.query(0, 2)
[1, 2, 3]
"""
from __future__ import annotations
from collections.abc import Callable

View File

@ -6,6 +6,7 @@ We will use the formula: t(n) = SUMMATION(i = 1 to n)t(i-1)t(n-i)
Further details at Wikipedia: https://en.wikipedia.org/wiki/Catalan_number
"""
"""
Our Contribution:
Basically we Create the 2 function:

View File

@ -2,6 +2,7 @@
psf/black : true
ruff : passed
"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -3,6 +3,7 @@ Segment_tree creates a segment tree with a given array and function,
allowing queries to be done later in log(N) time
function takes 2 values and returns a same type value
"""
from collections.abc import Sequence
from queue import Queue

View File

@ -4,6 +4,7 @@ Given the root of a binary tree, check whether it is a mirror of itself
Leetcode reference: https://leetcode.com/problems/symmetric-tree/
"""
from __future__ import annotations
from dataclasses import dataclass

View File

@ -7,6 +7,7 @@ such as the with segment trees or fenwick trees. You can read more about them he
2. https://www.youtube.com/watch?v=4aSv9PcecDw&t=811s
3. https://www.youtube.com/watch?v=CybAgVF-MMc&t=1178s
"""
from __future__ import annotations
test_array = [2, 1, 4, 5, 6, 0, 8, 9, 1, 2, 0, 6, 4, 2, 0, 6, 5, 3, 2, 7]

View File

@ -58,6 +58,7 @@ The probability decreases with the number of bits in the bitarray.
>>> bloom.bitstring
'01100101'
"""
from hashlib import md5, sha256
HASH_FUNCTIONS = (sha256, md5)

View File

@ -11,6 +11,7 @@ Where hash1() and hash2() are hash functions and TABLE_SIZE is size of hash tabl
Reference: https://en.wikipedia.org/wiki/Double_hashing
"""
from .hash_table import HashTable
from .number_theory.prime_numbers import is_prime, next_prime

View File

@ -7,6 +7,7 @@ Another hash map implementation, with a good explanation.
Modern Dictionaries by Raymond Hettinger
https://www.youtube.com/watch?v=p33CVV29OG8
"""
from collections.abc import Iterator, MutableMapping
from dataclasses import dataclass
from typing import Generic, TypeVar

View File

@ -5,6 +5,7 @@ Nodes contain data and also may link to other nodes:
head node gives us access of the complete list
- Last node: points to null
"""
from __future__ import annotations
from typing import Any

View File

@ -1,6 +1,7 @@
"""
Algorithm that merges two sorted linked lists into one sorted linked list.
"""
from __future__ import annotations
from collections.abc import Iterable, Iterator

View File

@ -2,6 +2,7 @@
Based on "Skip Lists: A Probabilistic Alternative to Balanced Trees" by William Pugh
https://epaperpress.com/sortsearch/download/skiplist.pdf
"""
from __future__ import annotations
from random import random

View File

@ -1,6 +1,7 @@
"""
Implementation of double ended queue.
"""
from __future__ import annotations
from collections.abc import Iterable

View File

@ -1,4 +1,5 @@
"""A Queue using a linked list like structure"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -1,4 +1,5 @@
"""Queue represented by a pseudo stack (represented by a list with pop and append)"""
from typing import Any

View File

@ -29,6 +29,7 @@ RULE 5: When the entire infix expression has been scanned, the value left on
NOTE: It only works with whole numbers.
"""
__author__ = "Alexander Joslin"
import operator as op

View File

@ -1,4 +1,5 @@
"""A Stack using a linked list like structure"""
from __future__ import annotations
from collections.abc import Iterator

View File

@ -1,6 +1,7 @@
"""
Implemented an algorithm using opencv to convert a colored image into its negative
"""
from cv2 import destroyAllWindows, imread, imshow, waitKey

View File

@ -1,6 +1,7 @@
"""
Implementation Burke's algorithm (dithering)
"""
import numpy as np
from cv2 import destroyAllWindows, imread, imshow, waitKey

View File

@ -9,6 +9,7 @@ Inputs:
Output:
img:A 2d zero padded image with values in between 0 and 1
"""
import math
import sys

View File

@ -1,6 +1,7 @@
"""
Implementation of gaussian filter algorithm
"""
from itertools import product
from cv2 import COLOR_BGR2GRAY, cvtColor, imread, imshow, waitKey

View File

@ -1,6 +1,7 @@
"""
Implementation of median filter algorithm
"""
from cv2 import COLOR_BGR2GRAY, cvtColor, imread, imshow, waitKey
from numpy import divide, int8, multiply, ravel, sort, zeros_like

View File

@ -3,6 +3,7 @@ Created on Fri Sep 28 15:22:29 2018
@author: Binish125
"""
import copy
import os

View File

@ -1,4 +1,5 @@
"""Multiple image resizing techniques"""
import numpy as np
from cv2 import destroyAllWindows, imread, imshow, waitKey

View File

@ -1,6 +1,7 @@
"""
Implemented an algorithm using opencv to tone an image with sepia technique
"""
from cv2 import destroyAllWindows, imread, imshow, waitKey

View File

@ -1,6 +1,7 @@
"""
PyTest's for Digital Image Processing
"""
import numpy as np
from cv2 import COLOR_BGR2GRAY, cvtColor, imread
from numpy import array, uint8

View File

@ -12,6 +12,7 @@ There are other several other algorithms for the convex hull problem
which have not been implemented here, yet.
"""
from __future__ import annotations
from collections.abc import Iterable

View File

@ -8,6 +8,7 @@ This is a divide and conquer algorithm that can find a solution in O(n) time.
For more information of this algorithm:
https://web.stanford.edu/class/archive/cs/cs161/cs161.1138/lectures/08/Small08.pdf
"""
from __future__ import annotations
from random import choice

View File

@ -6,6 +6,7 @@ maximum sum within a given array of numbers. For example, given the array
This divide-and-conquer algorithm finds the maximum subarray in O(n log n) time.
"""
from __future__ import annotations
import time

View File

@ -7,6 +7,7 @@ to find the maximum of the array.
(From Kleinberg and Tardos. Algorithm Design.
Addison Wesley 2006: Chapter 5 Solved Exercise 1)
"""
from __future__ import annotations

View File

@ -2,6 +2,7 @@
Program to list all the ways a target string can be
constructed from the given list of substrings
"""
from __future__ import annotations

View File

@ -8,6 +8,7 @@ We have N tasks and M people. Each person in M can do only certain of these task
a person can do only one task and a task is performed only by one person.
Find the total no of ways in which the tasks can be distributed.
"""
from collections import defaultdict

View File

@ -4,6 +4,7 @@
This program calculates the nth Fibonacci number in O(log(n)).
It's possible to calculate F(1_000_000) in less than a second.
"""
from __future__ import annotations
import sys

View File

@ -5,6 +5,7 @@ You are given a bitmask m and you want to efficiently iterate through all of
its submasks. The mask s is submask of m if only bits that were included in
bitmask are set
"""
from __future__ import annotations

View File

@ -10,6 +10,7 @@ return it.
Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return
[10, 22, 33, 41, 60, 80] as output
"""
from __future__ import annotations

View File

@ -38,6 +38,7 @@ Example input:
arr = [40, 20, 30, 10, 30]
output: 26000
"""
from collections.abc import Iterator
from contextlib import contextmanager
from functools import cache

View File

@ -9,6 +9,7 @@ subarray sum problem in O(n) time and O(1) space.
Reference: https://en.wikipedia.org/wiki/Maximum_subarray_problem
"""
from collections.abc import Sequence

View File

@ -14,6 +14,7 @@ represented as τ (tau). By using this RC-timeconstant we can find the voltage
time 't' from the initiation of charging a capacitor with the help of the exponential
function containing RC. Both at charging and discharging of a capacitor.
"""
from math import exp # value of exp = 2.718281828459…

View File

@ -25,6 +25,7 @@ when inductor is connected across 'AC' potential source. It starts to store the
in its 'magnetic field'.with the help 'RL-time-constant' we can find current at any time
in inductor while it is charging.
"""
from math import exp # value of exp = 2.718281828459…

View File

@ -58,6 +58,7 @@ Sources :
https://learn.parallax.com/support/reference/resistor-color-codes
https://byjus.com/physics/resistor-colour-codes/
"""
valid_colors: list = [
"Black",
"Brown",

View File

@ -6,6 +6,7 @@ and identify trends.
Reference: https://en.wikipedia.org/wiki/Moving_average
"""
from collections.abc import Sequence

View File

@ -20,7 +20,6 @@ Requirements (pip):
- numpy
"""
from __future__ import annotations
import matplotlib.pyplot as plt # type: ignore

View File

@ -15,7 +15,6 @@ the boundary of the Mandelbrot set a fractal curve.
(see also https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set )
"""
import colorsys
from PIL import Image # type: ignore

View File

@ -22,6 +22,7 @@ Credits:
This code was written by editing the code from
https://www.riannetrujillo.com/blog/python-fractal/
"""
import sys
import turtle

View File

@ -10,7 +10,6 @@ Reference: shorturl.at/exHM7
# Author: Swayam Singh (https://github.com/practice404)
from queue import PriorityQueue
from typing import Any

View File

@ -1,6 +1,7 @@
"""
https://en.wikipedia.org/wiki/Bidirectional_search
"""
from __future__ import annotations
import time

View File

@ -1,6 +1,7 @@
"""
https://en.wikipedia.org/wiki/Bidirectional_search
"""
from __future__ import annotations
import time

View File

@ -24,6 +24,7 @@
Details: https://en.wikipedia.org/wiki/Bor%C5%AFvka%27s_algorithm
"""
from __future__ import annotations
from typing import Any

View File

@ -1,6 +1,7 @@
#!/usr/bin/python
"""Author: OMKAR PATHAK"""
from __future__ import annotations
from queue import Queue

View File

@ -12,6 +12,7 @@ while Q is non-empty:
mark w as explored
add w to Q (at the end)
"""
from __future__ import annotations
from collections import deque

View File

@ -1,6 +1,7 @@
"""Breath First Search (BFS) can be used when finding the shortest path
from a given source node to a target node in an unweighted graph.
"""
from __future__ import annotations
graph = {

View File

@ -4,6 +4,7 @@
Manual test:
python bfs_shortest_path.py
"""
demo_graph = {
"A": ["B", "C", "E"],
"B": ["A", "D", "E"],

View File

@ -3,6 +3,7 @@ Finding the shortest path in 0-1-graph in O(E + V) which is faster than dijkstra
0-1-graph is the weighted graph with the weights equal to 0 or 1.
Link: https://codeforces.com/blog/entry/22276
"""
from __future__ import annotations
from collections import deque

View File

@ -9,6 +9,7 @@ Return a deep copy (clone) of the graph.
Each node in the graph contains a value (int) and a list (List[Node]) of its
neighbors.
"""
from dataclasses import dataclass

View File

@ -1,4 +1,5 @@
"""Non recursive implementation of a DFS algorithm."""
from __future__ import annotations

View File

@ -30,6 +30,7 @@ only the distance between previous vertex and current vertex but the entire
distance between each vertex that makes up the path from start vertex to target
vertex.
"""
import heapq

View File

@ -12,6 +12,7 @@ Constraints
Note: The tree input will be such that it can always be decomposed into
components containing an even number of nodes.
"""
# pylint: disable=invalid-name
from collections import defaultdict

View File

@ -8,6 +8,7 @@ frequent subgraphs and maximum common subgraphs.
URL: https://www.researchgate.net/publication/235255851
"""
# fmt: off
edge_array = [
['ab-e1', 'ac-e3', 'ad-e5', 'bc-e4', 'bd-e2', 'be-e6', 'bh-e12', 'cd-e2', 'ce-e4',

View File

@ -15,6 +15,7 @@ Potential Future Ideas:
- Make edge weights and vertex values customizable to store whatever the client wants
- Support multigraph functionality if the client wants it
"""
from __future__ import annotations
import random

View File

@ -15,6 +15,7 @@ Potential Future Ideas:
- Make edge weights and vertex values customizable to store whatever the client wants
- Support multigraph functionality if the client wants it
"""
from __future__ import annotations
import random

Some files were not shown because too many files have changed in this diff Show More