python - Trying to find all possible combinations and groupings -


i have been trying work through following problem using excel , realized may better suited python however, not sure start, have basic understanding of python. how guys approach solving this?

there 6 kinds of coffee , there 10 kinds of flavor shots , can put one, 2 or 3 shots in each kind of coffee. based on this, know (and list) unique flavor combinations , how long go without having same cup of coffee.

using itertools.combinations can different possibly combinations of flavour shot:

from itertools import combinations  shots = range(1,11) n = 3  coms = [c n in range(1, n+1) c in combinations(shots, n)] 

the length of coms give number of combinations, in case of 6 flavours , one, two, or 3 shots 175.

the number of flavour shot combinations when added coffee 6 * 175 = 1050.

edit

additionally (as aside) don't need through programming. assuming have n elements , want work out how many different ways can pick k of them number given binomial coefficient can calculated c(n, k) = n!/(k!*(n-k)!),

in case have n=10 , k=1, k=2, , k=3. solution is:

c(10, {1, 2, 3}) = c(10, 3) + c(10, 2) + c(10, 1)                  = 10!/(3!*(10-3)!) + 10!/(2!*(10-2)!) + 10!/(1!*(10-1)!)                  = 175            total = 175 * 6 = 1050 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -