Created
March 13, 2020 21:03
-
-
Save feliperobledo/f44448980d9efd0d1c7f1285e9f97b95 to your computer and use it in GitHub Desktop.
solution_distinct_positive_integers.py
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 pprint import pprint as pp | |
s1 = set([3, 5, 10, 20, 21]) | |
s2 = set([1, 3, 6, 24]) | |
memoization = {} | |
def get_prime_set(query_set): | |
prime_set = [] | |
for s in query_set: | |
subset = set([]) | |
for k in query_set: | |
if s == k: | |
continue | |
min_num = min(s,k) | |
max_num = max(s,k) | |
result = memoization.get((max_num, min_num), None) | |
if not result: | |
result = max_num % min_num | |
memoization[(max_num,min_num)] = result | |
if result == 0: | |
subset.add(min_num) | |
subset.add(max_num) | |
prime_set.append(subset) | |
return prime_set | |
a1 = get_prime_set(s1) | |
a1.sort(key=lambda x: len(x), reverse=True) | |
pp(a1[0]) | |
a2 = get_prime_set(s2) | |
a2.sort(key=lambda x: len(x), reverse=True) | |
pp(a2[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment