Last active
August 29, 2015 14:27
-
-
Save dmattosr/5ae56902a7309958df33 to your computer and use it in GitHub Desktop.
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
def pos(fila, columna, filas, columnas, lista=None): | |
if not lista: | |
lista = range(filas*columnas) | |
if not filas * columnas <= len(lista): | |
print 'Error: verificar filas * columnas <= len(lista)' | |
if not fila < filas: | |
print 'Error: verificar fila < filas' | |
elif not columna < columnas: | |
print 'Error: verficar columna < columnas' | |
else: | |
return l[columnas*fila + columna] | |
def left_top(fila, columna, filas, columnas, lista=None): | |
return pos(fila, columna, filas, columnas, lista) | |
def right_top(fila, columna, filas, columnas, lista=None): | |
return pos(fila, columnas - columna -1, filas, columnas, lista) | |
def left_down(fila, columna, filas, columnas, lista=None): | |
return pos(filas - fila -1, columna, filas, columnas, lista) | |
def right_down(fila, columna, filas, columnas, lista=None): | |
return pos(filas - fila -1, columnas - columna -1, filas, columnas, lista) | |
l = [10, 11, 12, 13, 14, 15, | |
16, 17, 18, 19, 20, 21, | |
22, 23, 24, 25, 26, 27, | |
38, 39, 30, 31, 32, 33] | |
print left_top(2, 0, 4, 6, l) | |
print right_top(0, 2, 4, 6, l) | |
print left_down(0, 2, 4, 6, l) | |
print right_down(0, 0, 4, 6, l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment