Add typehints to blockchain (#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>
This commit is contained in:
Jenia Dysin 2020-11-29 18:20:54 +02:00 committed by GitHub
parent e07766230d
commit 0febbd397e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

View File

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

View File

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

View File

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