Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Moleri <pmoleri@PABLOMOLERI-PC.(none)>2009-07-02 17:52:43 (GMT)
committer Pablo Moleri <pmoleri@PABLOMOLERI-PC.(none)>2009-07-02 17:52:43 (GMT)
commitc655ca9d723fbf7b1a7f4ccd86681ff4be35923a (patch)
tree5e2d9c438736a161400e209647fe50f771ea1382
Initial
-rw-r--r--doc/parentesiscurvo.pdfbin0 -> 151344 bytes
-rw-r--r--doc/reglasde_validacion.pdfbin0 -> 37612 bytes
-rw-r--r--parentesis.activity/parserparentesis.py144
-rw-r--r--resources/Python_para_todos.pdfbin0 -> 1272911 bytes
4 files changed, 144 insertions, 0 deletions
diff --git a/doc/parentesiscurvo.pdf b/doc/parentesiscurvo.pdf
new file mode 100644
index 0000000..5c37b39
--- /dev/null
+++ b/doc/parentesiscurvo.pdf
Binary files differ
diff --git a/doc/reglasde_validacion.pdf b/doc/reglasde_validacion.pdf
new file mode 100644
index 0000000..9d4a51e
--- /dev/null
+++ b/doc/reglasde_validacion.pdf
Binary files differ
diff --git a/parentesis.activity/parserparentesis.py b/parentesis.activity/parserparentesis.py
new file mode 100644
index 0000000..aefe5fe
--- /dev/null
+++ b/parentesis.activity/parserparentesis.py
@@ -0,0 +1,144 @@
+import re
+import random
+import types
+
+### Version 0.2
+## modulo logico
+
+## Definicion a manopla para formulas de nivel 1
+pattern1 = "\S*\(\S*\+\S*\)\S*" # ( ... + ... ) al menos un mas en el medio
+pattern2 = "(\+\)|\*\)|\(\+|\(\*)" # ni (+ ni (* ni +) ni *)
+pattern3 = "^\(\w*\)$" # parentesis al principio y parentesis al final
+
+CANT_NUM = 6
+def imprimirConfiguracion():
+ """Usada para debug, muestra informacion del modulo"""
+ print "CONSTANTES"
+ print "CANT_NUM ", CANT_NUM
+ print "OPERANDOS", CANT_NUM - 1
+
+
+#Tal vez deba recibir un parametro NIVEL y en funcion de eso validar o no el string.
+def validarString(s):
+ """Si el string s es valido segun las convenciones lo devuelve, sino da none
+
+ Returns string"""
+ if re.search(pattern2, s):
+ return None
+ if re.search(pattern3, s):
+ return None
+ if re.search(pattern1, s):
+ return s
+ return None # en caso contrario devuelve nada
+
+
+##Funcion que testea las validaciones para todo el conjunto generado a mano de parentesis posibles
+## en un conjunto de 6 numeros
+def testearValidarStringNivelUno():
+ print "COMIENZA TEST DE VALIDACION DE LECTOR DE STRING..."
+ str1 = "(1*2+3)*4+5*6"
+ str2 = "(1*2+3*4)+5*6"
+ str3 = "(1*2+3*4+5)*6"
+ str4 = "1*(2+3)*4+5*6"
+ str5 = "1*(2+3*4)+5*6"
+ str6 = "1*(2+3*4+5)*6"
+ str7 = "1*(2+3*4+5*6)"
+ str8 = "1*2+(3*4+5)*6"
+ str9 = "1*2+(3*4+5*6)"
+ str10= "1*2+3*(4+5)*6"
+ str11= "1*2+3*(4+5*6)"
+ listaStr = [str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11]
+ errores = [validarString(s) for s in listaStr]
+ if errores.count(None):
+ print "Hay errores de validacion!, verificar str1 .. str11"
+ else:
+ print "TEST OK"
+ print "FIN DEL TEST!"
+
+if __name__ == "__main__":
+ testearValidarStringNivelUno();
+
+#notar los parametros opcionales ---remover---
+def generarListaNum(cant_num = CANT_NUM, rango_max = 9):
+ """genera una lista de tamano cant_num, con numeros entre 2 y rango_max
+ uqe no pueden estar repetidos"""
+ if cant_num + 1 > rango_max:
+ return None ### deberia de tirar una excepcion esto es MAL ESTILO TO DO
+ lista = []
+ while len(lista) < cant_num:
+ num = random.randint(2,rango_max)
+ if not lista.count(num):
+ lista.append(num)
+ return lista
+
+def generarListaOp(cant_op = CANT_NUM - 1):
+ """ genera una lista de largo cant_op alternando * y +, empezando por *"""
+ i = 1
+ lista = []
+ while i <= cant_op:
+ if i % 2:
+ lista.append('*')
+ else:
+ lista.append('+')
+ i += 1
+ return lista
+
+def alternarElementosLista(lst1, lst2):
+ """ alterna los elementos de las listas, generando una lista nueva
+ PRE: len(lst1) >= len(lst2)
+ Retorna la lista con los elementos alternados"""
+ lista = []
+ largo = len(lst2)
+ i = 0
+ while i < largo:
+ lista.append(lst1[i])
+ lista.append(lst2[i])
+ i += 1
+ #si quedan elementos en la lista 1 los agrego
+ largoNuevo = len(lst1)
+ while i < largoNuevo:
+ lista.append(lst1[i])
+ i += 1
+ return lista
+
+
+### TOTALMENTE INCOMPLETA
+def generarCasos(cant_num = CANT_NUM, nivel = 1): ## TO DO!
+ """Recibe un numero y devuelve una lista con todos los casos posibles y con
+ los parentesis bien puestos"""
+ listaNum = generarListaNum()
+ listaOp = generarListaOp()
+ res = alternarElementosLista(listaNum, listaOp)
+
+ if nivel == 1:
+ return None
+ return None
+### Ejemplo de devolucion lista = ["(1*2+3)*4 + 5 * 6", "1*2+3 * (4+5)*6"]
+
+
+def buscarProxNum(lista, start = 0):
+ """Devuelve el proximo indice en la lista donde hay un numero
+ PRE: len(lista) > start
+ """
+
+ lst = lista[start:]
+ i = start
+ while len(lst) > 0 and type(lst.pop(0)) != types.IntType:
+ i += 1
+ return i
+
+
+### Pongo parentesis en el primer lugar que pueda --busco siguiente lugar con "numero a la derecha"
+ ### Busco indice para el segundo lugar --recorro lista
+ ### Si encuentro pongo y mando a testear/agregar
+ ### Si no encuentro indice, avanzo el primer indice
+ ###
+
+### [8, '*', 2, '+', 6, '*', 7, '+', 9, '*', 4]
+
+
+listaNum = generarListaNum()
+listaOp = generarListaOp()
+res = alternarElementosLista(listaNum, listaOp)
+
+
diff --git a/resources/Python_para_todos.pdf b/resources/Python_para_todos.pdf
new file mode 100644
index 0000000..548af05
--- /dev/null
+++ b/resources/Python_para_todos.pdf
Binary files differ