Skip to content

Instantly share code, notes, and snippets.

@dmattosr
Last active August 29, 2015 14:27
Show Gist options
  • Save dmattosr/5ae56902a7309958df33 to your computer and use it in GitHub Desktop.
Save dmattosr/5ae56902a7309958df33 to your computer and use it in GitHub Desktop.
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