Skip to content

Commit

Permalink
Merge pull request TheAlgorithms#136 from JuantAldea/euclidean_gcd
Browse files Browse the repository at this point in the history
Adding Euclidean GCD algorithm
  • Loading branch information
harshildarji authored Oct 17, 2017
2 parents 54eb79f + 2480eac commit 6882321
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions other/euclidean_gcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://en.wikipedia.org/wiki/Euclidean_algorithm

def euclidean_gcd(a, b):
while b:
t = b
b = a % b
a = t
return a

def main():
print("GCD(3, 5) = " + str(euclidean_gcd(3, 5)))
print("GCD(5, 3) = " + str(euclidean_gcd(5, 3)))
print("GCD(1, 3) = " + str(euclidean_gcd(1, 3)))
print("GCD(3, 6) = " + str(euclidean_gcd(3, 6)))
print("GCD(6, 3) = " + str(euclidean_gcd(6, 3)))

if __name__ == '__main__':
main()

0 comments on commit 6882321

Please sign in to comment.