Travis Wells
• Member for 4 years, 11 months
• Last seen more than 1 year ago
Stats
309
reputation
8k
reached
2
answers
16
questions
Loading…
Communities
View all
About
# 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')

This user doesn’t have any gold badges yet.
2
silver badges
10
bronze badges
2
Score
6
Posts
33
Posts %
2
Score
3
Posts
17
Posts %
2
Score
3
Posts
17
Posts %
2
Score
2
Posts
11
Posts %
2
Score
1
Posts
6
Posts %
0
Score
5
Posts
28
Posts %
Top posts
View all questions and answers
2
Apr 18, 2019
2
May 9, 2019
2
Jan 22, 2020
2
Nov 18, 2019
2
May 10, 2020
1
Apr 22, 2019
1
Apr 24, 2019
1
Jul 11, 2020
1
Jul 13, 2020
1
Aug 14, 2020
Top Meta posts
11
0
Top network posts
View all network posts