Created
February 13, 2012 03:20
-
-
Save kroger/1813260 to your computer and use it in GitHub Desktop.
Math and Music seminar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations, product, permutations, chain | |
from math import factorial | |
import functools | |
import operator | |
def prod(seq): | |
"""Product of a sequence.""" | |
return functools.reduce(operator.mul, seq, 1) | |
def sum_seq(to, fro): | |
return prod(range(fro, to+1)) | |
def powerset(iterable): | |
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" | |
s = list(iterable) | |
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) | |
def C(n, k): | |
return factorial(n)/(factorial(n - k) * factorial(k)) | |
def P(n, k): | |
return factorial(n)/factorial(n - k) | |
pw = list(powerset([0,1,2])) | |
p = list(product([0,4,7], [2,6,9], [4,8,11])) | |
comb = list(combinations([0, 1, 3, 4, 6, 7, 8, 10], 3)) | |
perm = list(permutations([0, 1, 3, 4, 6, 7, 8, 10], 3)) | |
#serie_perm = list(permutations([0,1,2,3,4,5,6,7,8,9,10,11], 12)) | |
serie_perm = permutations([0,1,2,3,4,5,6,7,8,9,10,11], 12) | |
for item in serie_perm: | |
print item | |
serie_power_set = list(powerset(range(0, 12))) | |
conjuntos = sum([C(12, x) for x in range(3, 12)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment