Facebook
From Dawid Dębowski, 3 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 47
  1. import math
  2.  
  3. def is_prime(n):
  4.     if n == 1 or n == 0:
  5.         return False
  6.     if n == 2:
  7.         return True
  8.     if n%2 == 0:
  9.         return False
  10.     for i in range(3, math.ceil(math.sqrt(n))):
  11.         if n%i == 0:
  12.             return False
  13.     return True
  14.  
  15.  
  16. def filter_function(elem, hash_b):
  17.     if elem not in hash_b:
  18.         return True
  19.     return not is_prime(hash_b[elem])
  20.  
  21.  
  22. def solution(a, b):
  23.     hash_b = {}
  24.     for elem in b:
  25.         if elem in hash_b:
  26.             hash_b[elem] += 1
  27.         else:
  28.             hash_b[elem] = 1
  29.     print(hash_b)
  30.     c = [elem for elem in a if filter_function(elem, hash_b)]
  31.     return c
  32.    
  33.  
  34. a = [2,3,9,2,5,1,3,7,10]
  35. b = [2,1,3,4,3,10,6,6,1,7,10,10,10]
  36. print(solution(a, b))
  37.