Fix mypy in #3149 (#3988) · silam/TheAlgorithmPython@06dad4f · GitHub
Skip to content

Commit 06dad4f

Browse files
authored
* Fix mypy in TheAlgorithms#3149 * Fix pre-commit
1 parent ba6310b commit 06dad4f

3 files changed

Lines changed: 67 additions & 62 deletions

File tree

blockchain/chinese_remainder_theorem.py

Lines changed: 12 additions & 9 deletions

blockchain/diophantine_equation.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the
2-
# diophantine equation a*x + b*y = c has a solution (where x and y are integers)
3-
# iff gcd(a,b) divides c.
1+
from typing import Tuple
42

5-
# GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )
63

7-
8-
def diophantine(a: int, b: int, c: int) -> (int, int):
4+
def diophantine(a: int, b: int, c: int) -> Tuple[float, float]:
95
"""
6+
Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the
7+
diophantine equation a*x + b*y = c has a solution (where x and y are integers)
8+
iff gcd(a,b) divides c.
9+
10+
GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )
11+
1012
>>> diophantine(10,6,14)
1113
(-7.0, 14.0)
1214
@@ -26,19 +28,19 @@ def diophantine(a: int, b: int, c: int) -> (int, int):
2628
return (r * x, r * y)
2729

2830

29-
# Lemma : if n|ab and gcd(a,n) = 1, then n|b.
30-
31-
# Finding All solutions of Diophantine Equations:
31+
def diophantine_all_soln(a: int, b: int, c: int, n: int = 2) -> None:
32+
"""
33+
Lemma : if n|ab and gcd(a,n) = 1, then n|b.
3234
33-
# Theorem : Let gcd(a,b) = d, a = d*p, b = d*q. If (x0,y0) is a solution of Diophantine
34-
# Equation a*x + b*y = c. a*x0 + b*y0 = c, then all the solutions have the form
35-
# a(x0 + t*q) + b(y0 - t*p) = c, where t is an arbitrary integer.
35+
Finding All solutions of Diophantine Equations:
3636
37-
# n is the number of solution you want, n = 2 by default
37+
Theorem : Let gcd(a,b) = d, a = d*p, b = d*q. If (x0,y0) is a solution of
38+
Diophantine Equation a*x + b*y = c. a*x0 + b*y0 = c, then all the
39+
solutions have the form a(x0 + t*q) + b(y0 - t*p) = c,
40+
where t is an arbitrary integer.
3841
42+
n is the number of solution you want, n = 2 by default
3943
40-
def diophantine_all_soln(a: int, b: int, c: int, n: int = 2) -> None:
41-
"""
4244
>>> diophantine_all_soln(10, 6, 14)
4345
-7.0 14.0
4446
-4.0 9.0
@@ -67,13 +69,12 @@ def diophantine_all_soln(a: int, b: int, c: int, n: int = 2) -> None:
6769
print(x, y)
6870

6971

70-
# Euclid's Lemma : d divides a and b, if and only if d divides a-b and b
71-
72-
# Euclid's Algorithm
73-
74-
7572
def greatest_common_divisor(a: int, b: int) -> int:
7673
"""
74+
Euclid's Lemma : d divides a and b, if and only if d divides a-b and b
75+
76+
Euclid's Algorithm
77+
7778
>>> greatest_common_divisor(7,5)
7879
1
7980
@@ -94,12 +95,11 @@ def greatest_common_divisor(a: int, b: int) -> int:
9495
return b
9596

9697

97-
# Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers
98-
# x and y, then d = gcd(a,b)
99-
100-
101-
def extended_gcd(a: int, b: int) -> (int, int, int):
98+
def extended_gcd(a: int, b: int) -> Tuple[int, int, int]:
10299
"""
100+
Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers
101+
x and y, then d = gcd(a,b)
102+
103103
>>> extended_gcd(10, 6)
104104
(2, -1, 2)
105105

blockchain/modular_division.py

Lines changed: 30 additions & 28 deletions

0 commit comments

Comments
 (0)