Created
August 8, 2016 00:08
-
-
Save gciruelos/db2662d58b05ec8cc4fdafbb915eeb3b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import itertools | |
import pprint | |
pp = pprint.PrettyPrinter(depth=6) | |
def creciente_estricta(l): | |
return all(x<y for x, y in zip(l, l[1:])) | |
def generar_matrices(p): | |
lista = itertools.permutations(range(2*p), 2*p) | |
lista = map(lambda x: list(map(lambda r: r+1, x)), lista) | |
matrices = map(lambda m: [m[i:i+2] for i in map(lambda x: 2*x, range(p))], | |
lista) | |
# Primera columna creciente. | |
matrices = filter(lambda m: creciente_estricta([fil[0] for fil in m]), | |
matrices) | |
# Todas las filas son crecientes. | |
matrices = filter(lambda m: all([creciente_estricta(fil) for fil in m]), matrices) | |
return list(matrices) | |
# Para correr: | |
# python -i matrices.py | |
# Si no te anda: | |
# python3 -i matrices.py | |
# Despues: | |
# >>> pp.pprint(generar_matrices(p)) | |
# Donde p es el p que vos quieras. | |
# Para ver la cantidad de matrices: | |
# >>> len(generar_matrices(p)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment