-
-
Save RecursiveG/e751f9eb3c4383e2747e9dc6bc3c058b to your computer and use it in GitHub Desktop.
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
from functools import reduce | |
def factors(n): | |
return set(filter(lambda x:n%x==0, range(1, n+1))) | |
def solve(a, b, c): | |
setA = set() if a%c==0 else reduce(set.union, map(factors,range(a, 1, -c)), set()) | |
setB = set() if b%c==0 else reduce(set.union, map(factors,range(b, 1, -c)), set()) | |
if len(setA) == 0 and len(setB) == 0: | |
return [-1] | |
elif len(setA) == 0: | |
return list(setB) | |
elif len(setB) == 0: | |
return list(setA) | |
else: | |
return list(setA & setB) | |
print(solve(3,5,3)) | |
# prints [1,2,5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment