Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import reduce
- from math import sqrt
- def is_fraction(of):
- return lambda n: of % n == 0
- def fractions(val):
- lst = list(filter(is_fraction(val), range(2, int(sqrt(val)) + 1)))
- return set(lst + list(map(div(val), lst)))
- def intersect(a, b):
- return a.intersection(b)
- def div(n):
- return lambda x: int(n / x)
- def common(*a):
- return sorted(reduce(intersect, [fractions(x) for x in a]))
- print(common(512, 1024))
Advertisement
Add Comment
Please, Sign In to add comment