Skip to content

Instantly share code, notes, and snippets.

@kozmonaut
Last active January 15, 2021 16:22
Show Gist options
  • Save kozmonaut/50c948c9ab5d180b2049 to your computer and use it in GitHub Desktop.
Save kozmonaut/50c948c9ab5d180b2049 to your computer and use it in GitHub Desktop.
Euclidean algorithm - Find a greatest common divisor
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