Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- from itertools import combinations
- from functools import reduce
- from operator import mul
- import math
- # Subset Product: Find all divisors of TARGET, output the SIZE of ALL K-sets that have product
- # equal to TARGET)
- TARGET = math.factorial(12)
- SET = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
- SET = set(SET)
- divisors = []
- for i in SET:
- if TARGET % i == 0:
- divisors.append(i)
- divisors = sorted(divisors)
- max_combo = []
- for a in divisors:
- max_combo.append(a)
- if reduce(mul,max_combo) >= TARGET:
- if reduce(mul,max_combo) > TARGET:
- max_combo.pop()
- break
- else:
- break
- count = 0
- for A in range(len(max_combo), 0, -1):
- if A <= len(divisors):
- for X in combinations(divisors, A):
- count = count + 1
- if reduce(mul, X) == TARGET:
- print(X, 'K-Size: ',len(X))
- quit()
- if A == len(max_combo):
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement