Advertisement
Guest User

no duplicate sums

a guest
Apr 9th, 2024
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import itertools
  2. import math
  3. def is_prime(n):
  4.     if n <= 1:
  5.         return False
  6.     elif n <= 3:
  7.         return True
  8.     elif n % 2 == 0 or n % 3 == 0:
  9.         return False
  10.     i = 5
  11.     while i * i <= n:
  12.         if n % i == 0 or n % (i + 2) == 0:
  13.             return False
  14.         i += 6
  15.     return True
  16. # Here I use odd primes only
  17. def get_primes_up_to_N(N):
  18.     primes = []
  19.     num = 3
  20.     while len(primes) < N:
  21.         if is_prime(num):
  22.             primes.append(num)
  23.         num += 1
  24.     return primes
  25.  
  26. N = 3
  27. while True:
  28.     primes = get_primes_up_to_N(N)
  29.     # Generate N distinct primes raised to 6
  30.     my_list = [prime ** 6 for prime in primes]
  31.     combinations = list(itertools.combinations(my_list, 3))
  32.     get_the_sums = []
  33.     for i in combinations:
  34.          get_the_sums.append(sum(i))
  35.     #See if get_the_sums has no duplicates
  36.     # If there is no duplicates then there should be no
  37.     # collisions for subset sum
  38.     print('The size of the Universe: ',N, 'No duplicate sums: ',len(get_the_sums) == len(set(get_the_sums)))
  39.     N = N + 3
  40.     if len(get_the_sums) != len(set(get_the_sums)):
  41.         break
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement