Skip to content

Instantly share code, notes, and snippets.

@vincetran96
Created June 3, 2017 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincetran96/bf8eea408e0bf01c65532450ebc4059c to your computer and use it in GitHub Desktop.
Save vincetran96/bf8eea408e0bf01c65532450ebc4059c to your computer and use it in GitHub Desktop.
Find GCD algo created by vietzerg - https://repl.it/GZtV/2
import functools
def factor(n):
i = 2
result = []
while i <= n:
while n % i == 0:
n = n // i
result.append(i)
i += 1
return result
def get_GCD(n, m):
result = functools.reduce(lambda x,y: x*y, set(factor(n)).intersection(set(factor(m))))
return result
print(get_GCD(967680, 840))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment