209
reputation
1
9

Travis Wells

# Subset-Product solver
# with minor improvements

import itertools 
import numpy

s = list(map(int, input('Enter numbers WITH SPACES: ').split(' ')))
print('enter target integer: ')
target = int(input())

# This chunk of code is meant to experiment with no instances
# in poly time.


for i in s:
  if i < 0:
    print('must only be positive integers')
    quit()



check = [];
if numpy.prod(s) % target == 0:
   check.append(target)
if len(check) < 1:
  print(target, 'is a FALSE subset product')
  quit()

if s.count(str(target)+str(' ')) > 0:
   print('yes')
else:
   print('no')
   quit()

def findsubsets(s, n): 
    return list(itertools.combinations(s, n)) 

# Driver Code 
n = len(s)


# This code snippet is a for loop. It also is intended to cut down execution
# time ounce it finds the target integer. (instead of creating all combinations)


res_2 = [];
for i in range(1, len(s)+1):
   if i > 1:
      var = (findsubsets(s, i))
      kk = list(map(numpy.prod, var))
      res_2.append(kk)
   if str(res_2).count(str(target)+str(',')) > 0:
      print('yes')
      quit()

if str(res_2).count(str(target)) > 0:
  print('yes')
1
answer
7
questions
~4k
people reached
  • Member for 8 months
  • 240 profile views
  • Last seen 15 hours ago

Top tags (12)

Score 2
Posts 2
Posts % 25
Score 2
Posts 1
Score 2
Posts 1
Score 2
Posts 1
Score 2
Posts 1
Score 0
Posts 4

Top posts (8) All Questions Answers | Votes Newest

Badges (10)

Gold

Silver

1

Rarest

Bronze

9

Rarest