# 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')
Member for 2 years, 4 months
114 profile views
Last seen Mar 2 at 1:18
- Retrocomputing 551 551 33 silver badges1111 bronze badges
- Code Review 419 419 22 silver badges77 bronze badges
- Computer Science 309 309 22 silver badges1010 bronze badges
- Stack Overflow 303 303 11 gold badge22 silver badges1111 bronze badges
- Skeptics 263 263 11 silver badge77 bronze badges
- View network profile
Top network posts
- 20 What kind of television set would work with the Commodore 64?
- 14 Would a replacement screen from a TRS-80 model 102 work for a model 100?
- 9 Converting integers into Unary Notation
- 8 How to make python halt once target product is found in subset?
- 8 Has the US unemployment rate reached 24.9%?
- 7 Who are the top mathematicians who were ignored due to their unconventional approach?
- 5 Solving Subset-Product in Python
- View more network posts →