Python - Generate binary list with itertools -


i want generate following output:

[11000] combinations these numbers, no doubles

   [11000]    [01100]    [00110]    [00011]    [10100]    .    .    . 

but cannot figure out how that. in problem list has 365 values 20 ones.

you have 365 possible positions place 20 ones. 1 way approach making 20-length combinations of 365 positions.

an example of how in code:

from itertools import combinations  n = 365 r = 20  indexes in combinations(range(n), r):     base = [0]*n     in indexes:         base[i] = 1     print(base) 

since "n choose r" problem, you'll have lots of possible combinations! calculate how many, use: n! / (r!(n-r)!) = 365! / (20!(365-20)!) = 426112827338828179808453831565930.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -