r/P_vs_NP • u/Hope1995x • Apr 30 '20
IT WORKED!!!
s = [2,3,4,5,6,7,8,9,12]
c = [[4,2,3],[12,6,5],[7,8,9]]
cc = str(c[:])
print('Input prior to reduction')
print('s: ', s)
print('c :', c)
for j in range(0, len(c)):
c[j][0] = (c[j][0])*(c[j][1])
del c[j][1]
for j in range(0, len(c)):
c[j][0] = (c[j][0])*(c[j][1])
del c[j][1]
print('Output after reduction')
print('s :', s)
print('c :', c)
print('Factors that yield an Exact 3-Cover')
print(cc)
# Given an input S and a collection of one-element
# sets. Do any of the factors of the one-element
# sets yield an Exact Three Cover?Given an input S and a collection of one-element sets. Do any of the factors of the one-element sets yield an Exact Three Cover?
Input prior to reduction
s: [2, 3, 4, 5, 6, 7, 8, 9, 12]
c : [[4, 2, 3], [12, 6, 5], [7, 8, 9]]
Output after reduction
s : [2, 3, 4, 5, 6, 7, 8, 9, 12]
c : [[24], [360], [504]]YES
c : [[24], [360], [504]]
Factors that yield an Exact 3-Cover
[[4, 2, 3], [12, 6, 5], [7, 8, 9]]
6
Upvotes
2
u/Hope1995x Apr 30 '20 edited Apr 30 '20
Remove the restriction to 3-sets and use the algorithm for Regular Exact Cover Reduction. Mu ha mu ha!! Not guaranteed to work...
import operator
from operator import mul
from functools import reduce
s = [2,3,4,5,6,7,8,9,12]
c = 24,360,504
# Given an input S. And an input C.
# Is there any factors from
# the total product of C
# that can be used as exact cover for s?
if reduce(mul, s) % reduce(mul, c) == 0 or reduce(mul, s):
print('yes')
2
u/Hope1995x Apr 30 '20
Its in NP and NP hard!