what improved doing combinations lexicographic method pointed list?
i put position now i indispensable enumerate illusory combinations pointed list. instance, genuine proceed be:
for [1,2,3]:
b [4,5,6,7,8,9]:
c [1,2]:
furnish (a,b,c)
this functional, nonetheless whole terms array lists used. here some-more concept approach:
from numpy import zeros, array, nonzero, max
make_subset = lambda x,y: [x[i][j] i,j enumerate(y)]
def combinations(items):
num_items = [len(i) - 1 i items]
state = zeros(len(items), dtype=int)
finished = array(num_items, dtype=int)
furnish grab_items(items, state)
while true:
state[-1] != num_items[-1]:
state[-1] += 1
furnish make_subset(items, state)
else:
incrementable = nonzero(state != finished)[0]
len(incrementable):
lift stopiteration
rightmost = max(incrementable)
state[rightmost] += 1
state[rightmost+1:] = 0
furnish make_subset(items, state)
any recommendations improved proceed reasons opposing above approach?
Comments
Post a Comment