I was given a weird task to find a product mix out of 33 different products to make a certain total sales value. The possible combination apparently is 2^33. When I used the code below it says "Memory Error". My win10 desktop has 64G memory installed. Good news is that I solved this problem by using Excel VBA, it took few hours to get the result. Does anyone has ideas to deal with this type of problem? Using a generator? or a PD dataframe? Thanks!
import numpy as np
import itertools, sys
a1 = [4435.48, 327.96, 23.26, 4136.78, 77.06, 158.73, 1389.34,
820.32, 888.33, 3735.7, 201.78, 31.17, 250.04, 87.17, 3230.95,
491.53, 47.11, 508.22, 52.22, 1255.98, 3755.11, 948.4, 905.44,
80.41, 1323.68, 528.57, 1474.4, 83.98, 756.87, 310.68, 27.86,]
n = len(a1)
lst = [list(i) for i in itertools.product([0, 1], repeat=n)]
for g in lst:
c = sum(np.multiply(g, a1))
if abs(c - 11833) < 1:
print (g)
sys.exit()