Skip to content

Instantly share code, notes, and snippets.

@gciruelos
Created August 8, 2016 00:08
Show Gist options
  • Save gciruelos/db2662d58b05ec8cc4fdafbb915eeb3b to your computer and use it in GitHub Desktop.
Save gciruelos/db2662d58b05ec8cc4fdafbb915eeb3b to your computer and use it in GitHub Desktop.
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