Skip to content

Commit 2480eac

Browse files
committed
Adding Euclidean GCD algorithm
1 parent aa8485b commit 2480eac

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: other/euclidean_gcd.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://en.wikipedia.org/wiki/Euclidean_algorithm
2+
3+
def euclidean_gcd(a, b):
4+
while b:
5+
t = b
6+
b = a % b
7+
a = t
8+
return a
9+
10+
def main():
11+
print("GCD(3, 5) = " + str(euclidean_gcd(3, 5)))
12+
print("GCD(5, 3) = " + str(euclidean_gcd(5, 3)))
13+
print("GCD(1, 3) = " + str(euclidean_gcd(1, 3)))
14+
print("GCD(3, 6) = " + str(euclidean_gcd(3, 6)))
15+
print("GCD(6, 3) = " + str(euclidean_gcd(6, 3)))
16+
17+
if __name__ == '__main__':
18+
main()

0 commit comments

Comments
 (0)