Skip to content
  • Sponsor TheAlgorithms/Python

  • Notifications You must be signed in to change notification settings
  • Fork 46.9k

Add typehints to blockchain #3149

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
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
8 changes: 4 additions & 4 deletions blockchain/chinese_remainder_theorem.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@


# Extended Euclid
def extended_euclid(a, b):
def extended_euclid(a: int, b: int) -> (int, int):
"""
>>> extended_euclid(10, 6)
(-1, 2)
@@ -29,7 +29,7 @@ def extended_euclid(a, b):


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

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


# Same a above using InvertingModulo
def chinese_remainder_theorem2(n1, r1, n2, r2):
def chinese_remainder_theorem2(n1: int, r1: int, n2: int, r2: int) -> int:
"""
>>> chinese_remainder_theorem2(5,1,7,3)
31
8 changes: 4 additions & 4 deletions blockchain/diophantine_equation.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
# GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )


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


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


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


def extended_gcd(a, b):
def extended_gcd(a: int, b: int) -> (int, int, int):
"""
>>> extended_gcd(10, 6)
(2, -1, 2)
12 changes: 6 additions & 6 deletions blockchain/modular_division.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
# Uses ExtendedEuclid to find the inverse of a


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


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

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


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


# Extended Euclid
def extended_euclid(a, b):
def extended_euclid(a: int, b: int) -> (int, int):
"""
>>> extended_euclid(10, 6)
(-1, 2)
@@ -119,7 +119,7 @@ def extended_euclid(a, b):
# Euclid's Algorithm


def greatest_common_divisor(a, b):
def greatest_common_divisor(a: int, b: int) -> int:
"""
>>> greatest_common_divisor(7,5)
1