Skip to content

Commit 0e73eb9

Browse files
Merge branch 'TheAlgorithms:master' into main
2 parents 77d586c + b203150 commit 0e73eb9

File tree

10 files changed

+18
-15
lines changed

10 files changed

+18
-15
lines changed

Diff for: DIRECTORY.md

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* [In Static Equilibrium](arithmetic_analysis/in_static_equilibrium.py)
66
* [Intersection](arithmetic_analysis/intersection.py)
77
* [Jacobi Iteration Method](arithmetic_analysis/jacobi_iteration_method.py)
8-
* [Junk](arithmetic_analysis/junk.py)
98
* [Lu Decomposition](arithmetic_analysis/lu_decomposition.py)
109
* [Newton Forward Interpolation](arithmetic_analysis/newton_forward_interpolation.py)
1110
* [Newton Method](arithmetic_analysis/newton_method.py)

Diff for: arithmetic_analysis/junk.py

Whitespace-only changes.

Diff for: cellular_automata/langtons_ant.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, width: int, height: int) -> None:
3030
self.board = [[True] * width for _ in range(height)]
3131
self.ant_position: tuple[int, int] = (width // 2, height // 2)
3232

33-
# Initially pointing left (similar to the the wikipedia image)
33+
# Initially pointing left (similar to the wikipedia image)
3434
# (0 = 0° | 1 = 90° | 2 = 180 ° | 3 = 270°)
3535
self.ant_direction: int = 3
3636

Diff for: compression/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Compression
22

33
Data compression is everywhere, you need it to store data without taking too much space.
4-
Either the compression lose some data (then we talk about lossy compression, such as .jpg) or it does not (and then it is lossless compression, such as .png)
4+
Either the compression loses some data (then we talk about lossy compression, such as .jpg) or it does not (and then it is lossless compression, such as .png)
55

6-
Lossless compression is mainly used for archive purpose as it allow storing data without losing information about the file archived. On the other hand, lossy compression is used for transfer of file where quality isn't necessarily what is required (i.e: images on Twitter).
6+
Lossless compression is mainly used for archive purpose as it allows storing data without losing information about the file archived. On the other hand, lossy compression is used for transfer of file where quality isn't necessarily what is required (i.e: images on Twitter).
77

88
* <https://www.sciencedirect.com/topics/computer-science/compression-algorithm>
99
* <https://en.wikipedia.org/wiki/Data_compression>

Diff for: computer_vision/haralick_descriptors.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def binarize(image: np.ndarray, threshold: float = 127.0) -> np.ndarray:
100100
return np.where(image > threshold, 1, 0)
101101

102102

103-
def transform(image: np.ndarray, kind: str, kernel: np.ndarray = None) -> np.ndarray:
103+
def transform(
104+
image: np.ndarray, kind: str, kernel: np.ndarray | None = None
105+
) -> np.ndarray:
104106
"""
105107
Simple image transformation using one of two available filter functions:
106108
Erosion and Dilation.
@@ -154,7 +156,7 @@ def transform(image: np.ndarray, kind: str, kernel: np.ndarray = None) -> np.nda
154156
return transformed
155157

156158

157-
def opening_filter(image: np.ndarray, kernel: np.ndarray = None) -> np.ndarray:
159+
def opening_filter(image: np.ndarray, kernel: np.ndarray | None = None) -> np.ndarray:
158160
"""
159161
Opening filter, defined as the sequence of
160162
erosion and then a dilation filter on the same image.
@@ -172,7 +174,7 @@ def opening_filter(image: np.ndarray, kernel: np.ndarray = None) -> np.ndarray:
172174
return transform(transform(image, "dilation", kernel), "erosion", kernel)
173175

174176

175-
def closing_filter(image: np.ndarray, kernel: np.ndarray = None) -> np.ndarray:
177+
def closing_filter(image: np.ndarray, kernel: np.ndarray | None = None) -> np.ndarray:
176178
"""
177179
Opening filter, defined as the sequence of
178180
dilation and then erosion filter on the same image.

Diff for: conversions/convert_number_to_words.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def max_value(cls, system: str) -> int:
5454

5555

5656
class NumberWords(Enum):
57-
ONES: ClassVar = {
57+
ONES: ClassVar[dict[int, str]] = {
5858
0: "",
5959
1: "one",
6060
2: "two",
@@ -67,7 +67,7 @@ class NumberWords(Enum):
6767
9: "nine",
6868
}
6969

70-
TEENS: ClassVar = {
70+
TEENS: ClassVar[dict[int, str]] = {
7171
0: "ten",
7272
1: "eleven",
7373
2: "twelve",
@@ -80,7 +80,7 @@ class NumberWords(Enum):
8080
9: "nineteen",
8181
}
8282

83-
TENS: ClassVar = {
83+
TENS: ClassVar[dict[int, str]] = {
8484
2: "twenty",
8585
3: "thirty",
8686
4: "forty",

Diff for: graphs/tarjans_scc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def create_graph(n, edges):
7777
n_vertices = 7
7878
source = [0, 0, 1, 2, 3, 3, 4, 4, 6]
7979
target = [1, 3, 2, 0, 1, 4, 5, 6, 5]
80-
edges = [(u, v) for u, v in zip(source, target)]
80+
edges = list(zip(source, target))
8181
g = create_graph(n_vertices, edges)
8282

8383
assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)

Diff for: hashes/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Unlike encryption, which is intended to protect data in transit, hashing is inte
77
This is one of the first algorithms that has gained widespread acceptance. MD5 is hashing algorithm made by Ray Rivest that is known to suffer vulnerabilities. It was created in 1992 as the successor to MD4. Currently MD6 is in the works, but as of 2009 Rivest had removed it from NIST consideration for SHA-3.
88

99
### SHA
10-
SHA stands for Security Hashing Algorithm and it’s probably best known as the hashing algorithm used in most SSL/TLS cipher suites. A cipher suite is a collection of ciphers and algorithms that are used for SSL/TLS connections. SHA handles the hashing aspects. SHA-1, as we mentioned earlier, is now deprecated. SHA-2 is now mandatory. SHA-2 is sometimes known has SHA-256, though variants with longer bit lengths are also available.
10+
SHA stands for Security Hashing Algorithm and it’s probably best known as the hashing algorithm used in most SSL/TLS cipher suites. A cipher suite is a collection of ciphers and algorithms that are used for SSL/TLS connections. SHA handles the hashing aspects. SHA-1, as we mentioned earlier, is now deprecated. SHA-2 is now mandatory. SHA-2 is sometimes known as SHA-256, though variants with longer bit lengths are also available.
1111

1212
### SHA256
1313
SHA 256 is a member of the SHA 2 algorithm family, under which SHA stands for Secure Hash Algorithm. It was a collaborative effort between both the NSA and NIST to implement a successor to the SHA 1 family, which was beginning to lose potency against brute force attacks. It was published in 2001.
1414
The importance of the 256 in the name refers to the final hash digest value, i.e. the hash value will remain 256 bits regardless of the size of the plaintext/cleartext. Other algorithms in the SHA family are similar to SHA 256 in some ways.
1515

1616
### Luhn
17-
The Luhn algorithm, also renowned as the modulus 10 or mod 10 algorithm, is a straightforward checksum formula used to validate a wide range of identification numbers, including credit card numbers, IMEI numbers, and Canadian Social Insurance Numbers. A community of mathematicians developed the LUHN formula in the late 1960s. Companies offering credit cards quickly followed suit. Since the algorithm is in the public interest, anyone can use it. The algorithm is used by most credit cards and many government identification numbers as a simple method of differentiating valid figures from mistyped or otherwise incorrect numbers. It was created to guard against unintentional errors, not malicious attacks.
17+
The Luhn algorithm, also renowned as the modulus 10 or mod 10 algorithm, is a straightforward checksum formula used to validate a wide range of identification numbers, including credit card numbers, IMEI numbers, and Canadian Social Insurance Numbers. A community of mathematicians developed the LUHN formula in the late 1960s. Companies offering credit cards quickly followed suit. Since the algorithm is in the public interest, anyone can use it. The algorithm is used by most credit cards and many government identification numbers as a simple method of differentiating valid figures from mistyped or otherwise incorrect numbers. It was created to guard against unintentional errors, not malicious attacks.

Diff for: machine_learning/xgboost_regressor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def xgboost(
2727
... 1.14300000e+03, 2.60958904e+00, 3.67800000e+01, -1.19780000e+02]]))
2828
array([[1.1139996]], dtype=float32)
2929
"""
30-
xgb = XGBRegressor(verbosity=0, random_state=42)
30+
xgb = XGBRegressor(
31+
verbosity=0, random_state=42, tree_method="exact", base_score=0.5
32+
)
3133
xgb.fit(features, target)
3234
# Predict target for test data
3335
predictions = xgb.predict(test_features)

Diff for: sorts/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ is specified by the sorting algorithm. The most typical orders are lexical or nu
44
of sorting lies in the fact that, if data is stored in a sorted manner, data searching can be highly optimised.
55
Another use for sorting is to represent data in a more readable manner.
66

7-
This section contains a lot of important algorithms that helps us to use sorting algorithms in various scenarios.
7+
This section contains a lot of important algorithms that help us to use sorting algorithms in various scenarios.
88
## References
99
* <https://www.tutorialspoint.com/python_data_structure/python_sorting_algorithms.htm>
1010
* <https://www.geeksforgeeks.org/sorting-algorithms-in-python>

0 commit comments

Comments
 (0)