Skip to content

Instantly share code, notes, and snippets.

@RecursiveG
Created June 23, 2016 07:40
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 RecursiveG/e751f9eb3c4383e2747e9dc6bc3c058b to your computer and use it in GitHub Desktop.
Save RecursiveG/e751f9eb3c4383e2747e9dc6bc3c058b to your computer and use it in GitHub Desktop.
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