From f4529bfe0ed441491b03b541e8595adaa30cc9ff Mon Sep 17 00:00:00 2001 From: DarĂ­o Clavijo Date: Tue, 25 May 2010 22:34:50 +0000 Subject: code transliterated to english --- diff --git a/data/math/factorial b/data/math/factorial index 9db469c..cdbd753 100644 --- a/data/math/factorial +++ b/data/math/factorial @@ -1,40 +1,40 @@ -#importamos la biblioteca que contiene las funciones para medir el tiempo de ejecucion +#we import the library containing functions for time measurement import timeit # inicializamos el timer t = timeit.Timer() -#definimos la funcion factorial recurrente -def factor_recurrente(n): - print "factorizando:",n - resultado = 1 +#we define a factor function in recursive flavor +def factorial_recursive(number): + result = 1 if n > 0: - resultado = n * factor_recurrente(n-1) - return resultado + result = n * factorial_recursive(number-1) + print "factorizing: ",number, " result: ", result + return result -#definimos la funcion factorial iterativa -def factor_iterativo(n): - resultado = 1 - for i in range(1,n+1): - print "factorizando:",i - resultado = resultado * i - return resultado +#we define a factor function in iterative flavor +def factorial_iterative(number): + result = 1 + for i in range(1,number+1): + result = result * i + print "factorizing: ",i, " result: ", result + return result -def calcular(n,tipo): - tiempo = t.timeit() - if tipo == 0: - tipo_s = "recurrente" - resultado = factor_recurrente(n) +def calculate(number,type): + time = t.timeit() + if type == 0: + type_s = "recursive" + result = factorial_recursive(number) else: - tipo_s = "iterativo" - resultado = factor_iterativo(n) - delta = abs(t.timeit() - tiempo) - print "factorial(",n,") = ", resultado, "tipo:" , tipo_s , " en: ", 1/delta + type_s = "iterative" + result = factorial_iterative(number) + delta = abs(t.timeit() - time) + print "Type: " , type_s , " in: ", 1/delta -#preguntamos el numero a factorizar -numero = input("Ingrese su numerito para calcular el factorial:") -print "Calculando..." -calcular(numero,0) -calcular(numero,1) +#we ask for a number to factorice +number = input("Please imput a number:") +print "Calculating..." +calculate(number,0) +calculate(number,1) diff --git a/data/misc/lifegame b/data/misc/lifegame index 77165df..fd93011 100644 --- a/data/misc/lifegame +++ b/data/misc/lifegame @@ -2,89 +2,110 @@ # Bibliotecas import os, time, random -def cargartablero(filas,columnas): - tablero=[] - columna = [0]*columnas - celulas=0 -#cargamos casilleros vacios - for i in range(filas): - columna = [0]* columnas - tablero.append(columna) -#cargamos las celulas - for x in range(filas): - for y in range(columnas): - celula = random.randint(0,random.randint(0,1)) - tablero[x][y] = celula - return tablero +# +# we need a funcion to load +# -def dibujartablero(tablero): - filas=len(tablero) - columnas=len(tablero[1]) - for x in range(filas): - for y in range(columnas): - if tablero[x][y]==0: +def LoadCells(rows,cols): + grid=[] + col = [0]*cols + cells=0 +#first we load an empty grid + for i in range(rows): + col = [0]* cols + grid.append(col) +#then we load some cells + for x in range(rows): + for y in range(cols): + cell = random.randint(0,random.randint(0,1)) + grid[x][y] = cell + return grid + +# +# here we draw the grid +# + +def DrawGrid(grid): + rows=len(grid) + cols=len(grid[1]) + for x in range(rows): + for y in range(cols): + if grid[x][y]==0: print ".", else: print "o", print "\n", -def contarvecinos(tablero,x,y): - vecinos=0 - filas=len(tablero) - columnas=len(tablero[1]) +# +# this funcion count neighbors arround a single cell +# + +def CountNeighbors(grid,x,y): + neighbors=0 + rows=len(grid) + cols=len(grid[1]) - if x < filas-1 and tablero[x+1][y]==1: - vecinos = vecinos + 1 - if x > 0 and tablero[x-1][y]==1: - vecinos = vecinos + 1 - if y < columnas-1 and tablero[x][y+1]==1: - vecinos = vecinos + 1 - if y > 0 and tablero[x][y-1]==1: - vecinos = vecinos + 1 - if x < filas-1 and y < columnas-1 and tablero[x+1][y+1]==1: - vecinos = vecinos + 1 - if x > 0 and y > 0 and tablero[x-1][y-1]==1: - vecinos = vecinos + 1 - if x > 0 and y < columnas-1 and tablero[x-1][y+1]==1: - vecinos = vecinos + 1 - if x < filas-1 and y > 0 and tablero[x+1][y-1]==1: - vecinos = vecinos + 1 + if x < rows-1 and grid[x+1][y]==1: + neighbors = neighbors + 1 + if x > 0 and grid[x-1][y]==1: + neighbors = neighbors + 1 + if y < cols-1 and grid[x][y+1]==1: + neighbors = neighbors + 1 + if y > 0 and grid[x][y-1]==1: + neighbors = neighbors + 1 + if x < rows-1 and y < cols-1 and grid[x+1][y+1]==1: + neighbors = neighbors + 1 + if x > 0 and y > 0 and grid[x-1][y-1]==1: + neighbors = neighbors + 1 + if x > 0 and y < cols-1 and grid[x-1][y+1]==1: + neighbors = neighbors + 1 + if x < rows-1 and y > 0 and grid[x+1][y-1]==1: + neighbors = neighbors + 1 - return vecinos + return neighbors -def iteracion(tablero): - filas=len(tablero) - columnas=len(tablero[1]) - vecinos=0 - for x in range(filas): - for y in range(columnas): - if tablero[x][y] == 1: - vecinos = contarvecinos(tablero,x,y) - if vecinos >= 3 and vecinos <= 6: +# here we define a single iteration +# if we have between 3 and 6 neighbors the single cell live +# in other case the cell die + +def Iteration(grid): + rows=len(grid) + cols=len(grid[1]) + neighbors=0 + for x in range(rows): + for y in range(cols): + if grid[x][y] == 1: + neighbors = CountNeighbors(grid,x,y) + if neighbors >= 3 and neighbors <= 6: xpos = x + random.randint(-1,1) if xpos <= 0: xpos = 1 - if xpos >= filas: - xpos = filas-1 + if xpos >= rows: + xpos = rows-1 ypos = y + random.randint(-1,1) if ypos <= 0: ypos = 1 - if ypos >= columnas: - ypos = columnas-1 - tablero[xpos][ypos]=1 + if ypos >= cols: + ypos = cols-1 + grid[xpos][ypos]=1 else: - tablero[x][y]=0 + grid[x][y]=0 + +# +# this funcion iterate n pulses and draws the result of earch one +# -def bucleprincipal(filas,columnas,pulsos): - pulso=0 - tablero = cargartablero(30,30) - while pulso < pulsos: +def Iterator(rows,cols,pulsos): + pulse=1 + grid = LoadCells(30,30) + while pulse <= pulses: os.system('clear') - print "Pulso: ",pulso - iteracion(tablero) - dibujartablero(tablero) - pulso = pulso + 1 + print "Pulse: ",pulse + Iteration(grid) + DrawGrid(grid) + pulse = pulse + 1 time.sleep(0.2) -numero = input("Ingrese el numero de filas y columnas (unico numero):") -pulsos = input("Ingrese el numero de pulsos:") -bucleprincipal(numero,numero,pulsos) + +number = input("Please imput the number of rows and cols (unique number):") +pulses = input("Please imput the number of pulses:") +Iterator(number,number,pulses) diff --git a/data/string/jeringoso b/data/string/jeringoso index 04f451a..e6ad0d5 100644 --- a/data/string/jeringoso +++ b/data/string/jeringoso @@ -1,10 +1,10 @@ -texto = raw_input("ingrese el texo para convertir a jeringoso:") -largo = len(texto) +text = raw_input("Please imput your text to translate to jeringoso:") +length = len(text) jeringoso="" -for i in range(largo): - letra = texto[i] - if letra == "a" or letra == "e" or letra == "i" or letra == "o" or letra == "u": - jeringoso = jeringoso + letra + "p" + letra +for i in range(length): + char = text[i] + if char == "a" or char == "e" or char == "i" or char == "o" or char == "u": + jeringoso = jeringoso + char + "p" + char else: - jeringoso = jeringoso + letra + jeringoso = jeringoso + char print jeringoso -- cgit v0.9.1