Last active
January 15, 2021 16:22
-
-
Save kozmonaut/50c948c9ab5d180b2049 to your computer and use it in GitHub Desktop.
Euclidean algorithm - Find a greatest common divisor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gcd(a,b): # Define function with two parameters | |
while b != 0: # Run loop till 'b' value is 0 | |
if a > b: # 'a' value must be larger than 'b' | |
r = a % b # Remainder value | |
a = b # Assign 'b' to 'a' | |
b = r # Asign remainder value to 'b' | |
return a # Return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment