Advertisement
Guest User

Reduction

a guest
Feb 22nd, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. from copy import deepcopy
  2. import math
  3.  
  4. # (No overlap) Decide if a subset of lists can be
  5. # multiplied together that will equal N.
  6.  
  7.  
  8. # Take any Exact-3-Cover Instance
  9. # for the Reduction
  10. s = [11,12,13,14,15,16]
  11. c = [[11,12,13],[14,15,16]]
  12.  
  13. s_copy = deepcopy(s)
  14. c_copy = deepcopy(c)
  15.  
  16. def bijective_mapp():
  17.     for a in range(0, len(s)):
  18.         s[a] = a+1
  19.     for b in range(0, len(c)):
  20.         for bb in range(0, len(c[b])):
  21.             c[b][bb] = s_copy.index(c[b][bb])+1
  22. bijective_mapp()
  23.  
  24. # Take the total product of s
  25. # Which is factorial(len(s))
  26.  
  27. N = math.factorial(len(s))
  28.  
  29. # We are going to need to convert N into
  30. # a Universe. To show that both N & S
  31. # can be reduced into each other
  32. # efficently
  33.  
  34. n = 0
  35. m = 1
  36. u = []
  37. while m < N:
  38.     n = n + 1
  39.     m = m * n
  40.     u.append(n)
  41.  
  42. if u == s:
  43.     print('Both u & s are equal')
  44.  
  45. print('input for N: ',N)
  46. print('input for c: ',c)
  47.  
  48. print('original inputs')
  49. print('s: ',s_copy)
  50. print('c: ',c_copy)
  51.  
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement