全组合

2017-07-21  本文已影响3人  hops

def fc(n):
'''find full combinations for 1-n,
using bitmap method. '''

comb = []
for i in range(2**n-1, 0, -1):
    b = str(bin(i))[2:].zfill(n)
    out = [range(1, n+1)[int(k)] for k, j in enumerate(b) if j == '1']
    comb.append(out)

return comb
上一篇 下一篇

猜你喜欢

热点阅读