Created
June 3, 2017 04:46
-
-
Save vincetran96/bf8eea408e0bf01c65532450ebc4059c to your computer and use it in GitHub Desktop.
Find GCD algo created by vietzerg - https://repl.it/GZtV/2
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
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