Skip to content

Commit 3977432

Browse files
jenia90github-actions
authored andcommitted
Add typehints to blockchain (TheAlgorithms#3149)
* updating DIRECTORY.md * updating DIRECTORY.md * Added type hints to blockchain algorithms * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent d30db78 commit 3977432

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Diff for: blockchain/chinese_remainder_theorem.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
# Extended Euclid
15-
def extended_euclid(a, b):
15+
def extended_euclid(a: int, b: int) -> (int, int):
1616
"""
1717
>>> extended_euclid(10, 6)
1818
(-1, 2)
@@ -29,7 +29,7 @@ def extended_euclid(a, b):
2929

3030

3131
# Uses ExtendedEuclid to find inverses
32-
def chinese_remainder_theorem(n1, r1, n2, r2):
32+
def chinese_remainder_theorem(n1: int, r1: int, n2: int, r2: int) -> int:
3333
"""
3434
>>> chinese_remainder_theorem(5,1,7,3)
3535
31
@@ -51,7 +51,7 @@ def chinese_remainder_theorem(n1, r1, n2, r2):
5151
# ----------SAME SOLUTION USING InvertModulo instead ExtendedEuclid----------------
5252

5353
# This function find the inverses of a i.e., a^(-1)
54-
def invert_modulo(a, n):
54+
def invert_modulo(a: int, n: int) -> int:
5555
"""
5656
>>> invert_modulo(2, 5)
5757
3
@@ -67,7 +67,7 @@ def invert_modulo(a, n):
6767

6868

6969
# Same a above using InvertingModulo
70-
def chinese_remainder_theorem2(n1, r1, n2, r2):
70+
def chinese_remainder_theorem2(n1: int, r1: int, n2: int, r2: int) -> int:
7171
"""
7272
>>> chinese_remainder_theorem2(5,1,7,3)
7373
31

Diff for: blockchain/diophantine_equation.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )
66

77

8-
def diophantine(a, b, c):
8+
def diophantine(a: int, b: int, c: int) -> (int, int):
99
"""
1010
>>> diophantine(10,6,14)
1111
(-7.0, 14.0)
@@ -37,7 +37,7 @@ def diophantine(a, b, c):
3737
# n is the number of solution you want, n = 2 by default
3838

3939

40-
def diophantine_all_soln(a, b, c, n=2):
40+
def diophantine_all_soln(a: int, b: int, c: int, n: int = 2) -> None:
4141
"""
4242
>>> diophantine_all_soln(10, 6, 14)
4343
-7.0 14.0
@@ -72,7 +72,7 @@ def diophantine_all_soln(a, b, c, n=2):
7272
# Euclid's Algorithm
7373

7474

75-
def greatest_common_divisor(a, b):
75+
def greatest_common_divisor(a: int, b: int) -> int:
7676
"""
7777
>>> greatest_common_divisor(7,5)
7878
1
@@ -98,7 +98,7 @@ def greatest_common_divisor(a, b):
9898
# x and y, then d = gcd(a,b)
9999

100100

101-
def extended_gcd(a, b):
101+
def extended_gcd(a: int, b: int) -> (int, int, int):
102102
"""
103103
>>> extended_gcd(10, 6)
104104
(2, -1, 2)

Diff for: blockchain/modular_division.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Uses ExtendedEuclid to find the inverse of a
1515

1616

17-
def modular_division(a, b, n):
17+
def modular_division(a: int, b: int, n: int) -> int:
1818
"""
1919
>>> modular_division(4,8,5)
2020
2
@@ -33,7 +33,7 @@ def modular_division(a, b, n):
3333

3434

3535
# This function find the inverses of a i.e., a^(-1)
36-
def invert_modulo(a, n):
36+
def invert_modulo(a: int, n: int) -> int:
3737
"""
3838
>>> invert_modulo(2, 5)
3939
3
@@ -51,7 +51,7 @@ def invert_modulo(a, n):
5151
# ------------------ Finding Modular division using invert_modulo -------------------
5252

5353
# This function used the above inversion of a to find x = (b*a^(-1))mod n
54-
def modular_division2(a, b, n):
54+
def modular_division2(a: int, b: int, n: int) -> int:
5555
"""
5656
>>> modular_division2(4,8,5)
5757
2
@@ -72,7 +72,7 @@ def modular_division2(a, b, n):
7272
# and y, then d = gcd(a,b)
7373

7474

75-
def extended_gcd(a, b):
75+
def extended_gcd(a: int, b: int) -> (int, int, int):
7676
"""
7777
>>> extended_gcd(10, 6)
7878
(2, -1, 2)
@@ -99,7 +99,7 @@ def extended_gcd(a, b):
9999

100100

101101
# Extended Euclid
102-
def extended_euclid(a, b):
102+
def extended_euclid(a: int, b: int) -> (int, int):
103103
"""
104104
>>> extended_euclid(10, 6)
105105
(-1, 2)
@@ -119,7 +119,7 @@ def extended_euclid(a, b):
119119
# Euclid's Algorithm
120120

121121

122-
def greatest_common_divisor(a, b):
122+
def greatest_common_divisor(a: int, b: int) -> int:
123123
"""
124124
>>> greatest_common_divisor(7,5)
125125
1

0 commit comments

Comments
 (0)