"""Programa Creado Por Marcos Ochoa Diez Para Symbian, Para Calcular Números Primos En Python Grabando A Fichero Los Resultados O Mostrándolos Por Pantalla Con La Opción Además De Enviar Cada X Minutos De Cálculo Como Va El Proceso A Otro Móvil Por MMS O Mediante Llamada Perdida Tambien Enviara Los Resultados Del Calculo En Curso Por MMS, Al Movil Que Pongamos Como Destinatario. El Programa Calculará Todo Tipo De Estadísticas Con Los Primos; Calculará Gemelos, Capicuas, Primos Que Leidos De IZQ A DRCHA Y Viceversa Son Primos A Su Vez, Primos Cuya Suma De Digitos Es A Su Vez Un Número Primo, Etc...""" import math, time import appuifw import e32 import mmsmodule import graphics import CallStatus import telephone from random import randint appuifw.app.title=u"^MvIiIaX^ Nº'S Primos I" appuifw.note(u"Bienvenid@ Al Programa De Cálculo De Nº's Primos Por Marcos Ochoa Diez. Espera...", "info" ) vector= [0] * 4792 terminacion = [0] * 10 terminacion1 =[0] * 10 quecositaes=0 divihechas=0 nosepuede=0 caguenlamar=0 fichero="" bilma="((( MvIiIaX 2006 )))" cuchi="Mensaje Enviado Tras Emitir Un Llamamiento Al Movil Que Calcula Primos, Desde Otro Movil Mediante Una Llamada Perdida... "+bilma def _raw_input( txt ): return appuifw.query( unicode( txt ), "text" ) def tiempo(n): semanas=n / 604800 diass=(n % 604800) / 86400; hor=((n % 604800) % 86400) / 3600; min=(((n % 604800) % 86400) % 3600) / 60; seg=(((n % 604800) % 86400) % 3600) % 60; return str(semanas)+"s"+str(diass)+"d"+str(hor)+"h"+str(min)+"m"+str(seg)+"s" def binarios(n): acumulador="" acumulador2="" acumulador=acumulador+str(n % 2) divisor=int(n/2) while divisor<>0: acumulador=acumulador+str(divisor %2) divisor=int(divisor/2) aaa = acumulador bbb = list(str(aaa)) bbb.reverse() ddd = "".join(bbb) return ddd def es_primo_m8ax( n ): j = int( round( math.sqrt( n ) ) ) for i in xrange(3, j+1, 2): if (n % i) == 0:return False return True def es_primo_mviiiax( n ): global divihechas raiz = int( round( math.sqrt( n ) ) ) loco=0 while (n % vector[loco]!=0 and vector[loco]<=raiz): loco+=1 divihechas+=1 if vector[loco]>raiz: return True ole=0 for mm in xrange(3,46350,2): if es_primo_m8ax( mm ): vector[ole]=mm ole +=1 porpantalla= int( _raw_input("Resultado 1-Pantalla 2-Fichero Con Opcion MMS: ") ) if porpantalla==2: avisarmovil=int( _raw_input("Aviso A Movil De Como Va El Proceso 1-SI 2-NO: ") ) lombarda=int( _raw_input("Escribir En MMC 1-SI 2-NO: ") ) wps1710=int( _raw_input("Cada Cuantos Segundos Sacamos Estad. Por Pantalla: ") ) else: avisarmovil=2 lombarda=2 wps1710=100 if lombarda==1: enbina=int( _raw_input(u"Añadir Fichero Con Los Primos En Binario 1-SI 2-NO: ") ) else: enbina=2 if avisarmovil==1 and porpantalla==2: cadacuanseg=int( _raw_input("Cada Cuantos Minutos Envio MMS: ") ) cadacuanseg=cadacuanseg*60 movil=int( _raw_input("Movil Al Que Enviaremos Cada "+str(cadacuanseg/60)+" Min Resultados: ") ) forma=int( _raw_input("1-Enviar Datos En Formato HTM O 2-Enviar De Forma Normal: ") ) appuifw.note(u"Aparte De Cada "+str(cadacuanseg/60)+" Min. El Movil Enviara Un MMS, Al "+str(movil)+" Cada Lla. Perd Que Reciba...", "info" ) for lulal in xrange(0,62000,1): wps1710=wps1710 if porpantalla==2 and lombarda==1: e32.ao_sleep(1) appuifw.note(u"Los Ficheros Resultantes Se Grabaran En La MMC En El Directorio Raiz", "info" ) f = open( "e:\\M8AX-S60-Primos.TxT", "w" ) f.write( "PROGRAMA CREADO POR M8AX PARA CALCULAR NUMEROS PRIMOS\n" ) f.write( "-----------------------------------------------------------\n" ) q = open( "e:\\M8AX-S60-PGemelos.TxT", "w" ) q.write( "NUMEROS PRIMOS GEMELOS CALCULADOS EN EL INTERVALO DADO\n" ) q.write( "-----------------------------------------------------------\n" ) l = open( "e:\\M8AX-S60-PriDrchaIzq.TxT", "w" ) l.write( "NUMEROS PRIMOS QUE LEIDOS TANTO DE IZQ A DRCH COMO DE DRCH A IZQ SON PRIMOS\n" ) l.write( "-----------------------------------------------------------\n" ) m = open( "e:\\M8AX-S60-SumaDigitosPrimos.TxT", "w" ) m.write( "NUMEROS PRIMOS CUYA SUMA DE SUS DIGITOS TAMBIEN ES UN NUMERO PRIMO\n" ) m.write( "-----------------------------------------------------------\n" ) if enbina==1: w = open( "e:\\M8AX-S60-PrimosBinarios.TxT", "w" ) w.write( "NUMEROS PRIMOS EN EL SISTEMA QUE ENTIENDEN LAS MAQUINAS OSEA EN BINARIO\n" ) w.write( "--------------------------------------------------------------------------\n" ) else: e32.ao_sleep(1) appuifw.note(u"Los Resultados Solo Saldran Por La Pantalla Del Movilete", "info" ) inicio = int( _raw_input("M8AX Dame El Numero De Comienzo: ") ) limite = int( _raw_input("M8AX Dame El Numero Final: ") ) if inicio0: if es_primo_mviiiax(sumacifras): cuantossumas+=1 concorde+=1 if porpantalla==2 and lombarda==1: if concorde==20: m.write( "%d, " % j) m.write( "\n" ) concorde=0 else: m.write( str(j)+", " ) puli=j if (j-anterior)==2: gemelos+=1 if porpantalla==2 and lombarda==1: q.write ("%d Y %d\n" % (anterior,j)) anterior=j terminacion[int(str(j)[-1:])] += 1 a = j b = list(str(a)) b.reverse() d = "".join(b) if long ( d ) > 2147483646: d=2 nosepuede+=1 if int(d) % 2 !=0: if es_primo_mviiiax( int(d) ): izde+=1 putita+=1 if putita == 20: if porpantalla==2 and lombarda==1: l.write( "\n") putita=0 if porpantalla==2 and lombarda==1: l.write( "%d, " % j ) if str(d)==str(j): capicua+=1 if str(d)==str(j): quehacemos=1 else: quehacemos=0 p = ( ( j - inicio ) / total) * 100.0 if quehacemos==0: if porpantalla==1: print "%d Es Numero Primo | %2.f%% Completado" % ( j, p ) if porpantalla==2 and lombarda==1: f.write( "%d, " % j ) cuenta += 1 cocoliso +=1 if cocoliso == 20: if porpantalla==2 and lombarda==1: f.write( "\n") cocoliso=0 else: if porpantalla==1: print "(%d) Es Numero Primo | %2.f%% Completado" % ( j, p ) if porpantalla==2 and lombarda==1: f.write( "(%d), " % j ) cocoliso +=1 cuenta+=1 if cocoliso == 20: if porpantalla==2 and lombarda==1: f.write( "\n") cocoliso=0 if porpantalla==2: restita=time.time()-start_t if restita % wps1710==0 and restita>0: if chupa==0:chupa=1 print "%2.f%% Completado\n" % ( p ) print "Primo En Curso. "+str(j) print "\nN. Primos Por Ahora. "+str(cuenta) print "\nDivis. Hechas. "+str(divihechas) print "\nTmp. On: ",tiempo(int(restita)) print "\nPr/Seg. "+str(cuenta/restita) print "\nDiv/Seg. "+str(divihechas/restita) tardara=((((total)/2)*restita)/chupa)-restita print "\nTmp. Off: ",tiempo(int(tardara)) if avisarmovil==1: resting=time.time()-startmms print "\nTmp Para Envio MMS. "+tiempo(abs(cadacuanseg-int(resting))) if (avisarmovil==1 and porpantalla==2): restita=time.time()-start_t if restita>1: if ((restita % cadacuanseg)==0) or (CallStatus.GetStatus()==5): if CallStatus.GetStatus()==5: caguenlamar=1 else: caguenlamar=2 thor = time.time() + time.clock()%1 hh1, mm2, ss3 = time.localtime(thor)[3:6] if forma<>1: quecositaes=randint(1,2) if quecositaes==1: im = graphics.screenshot() im.save(u"d:\\m8ax.jpg") e32.ao_yield() fichero="d:\\m8ax.jpg" else: fichero="e:\\system\\apps\\python\\m8axlogo.jpg" if chupa==0: chupa=1 tardara=((((total)/2)*restita)/chupa)-restita formas+=1 if caguenlamar==1: print "\n... Mandando MMS Con Resultados En Curso Tras Recibir Llamada Perdida ..." resting=time.time()-startmms lolonokia='Mensaje Numero ('+str(formas)+').'+' Hora: '+str(hh1)+':'+str(mm2)+':'+str(ss3)+' Primos Desde '+str(inicio)+' Hasta '+str(limite)+' Por Ahora Llevamos Calculados: '+str(cuenta)+' Numeros Primos. '+' Porcentaje Completado '+str(int(p))+' Por Ciento. Ultimo Primo Calculado '+str(puli)+'. PrimSeg: '+str(int(cuenta/(restita)))+'. Divisiones Realizadas Por El Momento: '+str(divihechas)+'. DiviSeg: '+str(int(divihechas/(restita)))+'. Primos Capicua Hasta Ahora: '+str(capicua)+'. Primos Gemelos Hasta Ahora: '+str(gemelos)+'. Primos Que Llevamos Que Leidos De Izquierda A Derecha Y Viceversa Son Primos: '+str(izde)+'. Primos Cuya Suma De Digitos Tambien Es Un Numero Primo: '+str(cuantossumas)+'. Tmp. Transcurrido: '+tiempo(int(restita))+'. Tiempo Que Mas O Menos Queda Para Que El Calculo Termine: '+tiempo(int(tardara))+'. El Siguiente MMS Se Enviara Dentro De '+tiempo(abs(cadacuanseg-int(resting))) +'. A No Ser Que El Calculo Termine Antes Avisandote Por MMS De Tal Circunstancia. '+cuchi else: print "\n... Mandando MMS Con Resultados En Curso ..." lolonokia='Mensaje Numero ('+str(formas)+').'+' Hora: '+str(hh1)+':'+str(mm2)+':'+str(ss3)+' Primos Desde '+str(inicio)+' Hasta '+str(limite)+' Por Ahora Llevamos Calculados: '+str(cuenta)+' Numeros Primos. '+' Porcentaje Completado '+str(int(p))+' Por Ciento. Ultimo Primo Calculado '+str(puli)+'. PrimSeg: '+str(int(cuenta/(restita)))+'. Divisiones Realizadas Por El Momento: '+str(divihechas)+'. DiviSeg: '+str(int(divihechas/(restita)))+'. Primos Capicua Hasta Ahora: '+str(capicua)+'. Primos Gemelos Hasta Ahora: '+str(gemelos)+'. Primos Que Llevamos Que Leidos De Izquierda A Derecha Y Viceversa Son Primos: '+str(izde)+'. Primos Cuya Suma De Digitos Tambien Es Un Numero Primo: '+str(cuantossumas)+'. Tmp. Transcurrido: '+tiempo(int(restita))+'. Tiempo Que Mas O Menos Queda Para Que El Calculo Termine: '+tiempo(int(tardara))+'. El Siguiente MMS Se Enviara Dentro De '+tiempo(int(cadacuanseg)) +'. A No Ser Que El Calculo Termine Antes Avisandote Por MMS De Tal Circunstancia. '+bilma if forma==1: KOKOL = open( "d:\\NotificacionPrimos-"+str(formas)+".HTM", "w" ) KOKOL.write(unicode(lolonokia)) KOKOL.close() mmsmodule.mms_send(unicode(str(movil)), unicode("NOTIFICACION PRIMOS"),unicode("d:\NotificacionPrimos-"+str(formas)+".HTM")) else: mmsmodule.mms_send(unicode(str(movil)), unicode(lolonokia),unicode(fichero)) if caguenlamar==2: startmms=time.time() restita=time.time()-start_t p = ( ( j - inicio ) / total) * 100.0 print "\n%2.f%% Completado" % ( p ) print "\nTmp. On: ",tiempo(int(restita)) if chupa==0: chupa = 1 tardara=((((total)/2)*restita)/chupa)-restita print "\nTmp. Off: ",tiempo(int(tardara)) print "\n" print restita, "... Segundos Procesando ...\n" print tiempo(int(restita)), "... Horas, Minutos Y Segundos De Proceso ...\n" gemelos=gemelos*2 if cuenta>0: for petroleo in xrange (0,10,1): terminacion1[petroleo]=(float(terminacion[petroleo])*float(100))/float(cuenta) if restita<1: restita=1 if porpantalla==2 and lombarda==1: f.write( "\n-----------------------------------------------------------" ) f.write( "\nSEGUNDOS EMPLEADOS EN EL CALCULO DE NUMEROS PRIMOS - " ) f.write ("%d\r\n" % restita) f.write( "TIEMPO EMPLEADO EN EL CALCULO DE NUMEROS PRIMOS - " ) f.write (tiempo(int(restita))) if enbina==1: w.write( "\n-----------------------------------------------------------" ) w.write( "\nNUMEROS PRIMOS EN BINARIO CALCULADOS - " ) w.write ("%d\r\n" % cuenta) w.write( "-----------------------------------------------------------" ) w.close() print "%d Primos Por Segundo Calculados\n" % int(cuenta/(restita)) if porpantalla==2 and lombarda==1: f.write( "\nPRIMOS POR SEGUNDO CALCULADOS EN EL INTERVALO DESDE %d HASTA %d - " % (inicio, limite )) f.write ("%d\r\n" % int(cuenta/(restita))) f.write( "NUMEROS PRIMOS CALCULADOS EN EL INTERVALO - " ) f.write ("%d\r\n" % cuenta) f.write( "NUMEROS PRIMOS CAPICUAS EN EL INTERVALO - " ) f.write ("%d\n" % capicua) f.write( "NUMEROS PRIMOS GEMELOS EN EL INTERVALO - " ) f.write ("%d\n" % gemelos) f.write( "NUMEROS PRIMOS QUE LEIDOS DE DRCH A IZQ Y DE IZQ A DRCH SON IGUALMENTE PRIMOS - " ) f.write ("%d\n" % izde) f.write( "NUMEROS PRIMOS QUE LEIDOS DE DRCH A IZQ Y DE IZQ A DRCH SON IGUALMENTE PRIMOS NO ANALIZADOS POR SUPERAR EL RANGO 2147483647 - " ) f.write ("%d\n" % nosepuede) f.write( "NUMEROS PRIMOS CUYA SUMA DE DIGITOS ES TAMBIEN NUMERO PRIMO - " ) f.write ("%d\n" % cuantossumas) f.write("DIVISIONES HECHAS PARA EL CALCULO TOTAL DE NUMEROS PRIMOS - ") f.write("%d\n" % divihechas) f.write("DIVISIONES POR SEGUNDO HECHAS DE MEDIA PARA EL CALCULO DE PRIMOS - ") f.write("%d\n" % int(divihechas/restita)) q.write( "-----------------------------------------------------------\n" ) q.write( "NUMEROS PRIMOS GEMELOS EN EL INTERVALO - " ) q.write ("%d\n" % gemelos) q.write( "-----------------------------------------------------------" ) l.write( "\n-----------------------------------------------------------" ) l.write( "\nNUMEROS PRIMOS QUE LEIDOS DE DRCH A IZQ Y DE IZQ A DRCH SON IGUALMENTE PRIMOS - " ) l.write ("%d\n" % izde) f.write( "TERMINACIONES DE LOS NUMEROS PRIMOS EN 0123456789 POR ORDEN - " ) f.write (str(terminacion)) f.write( "\nTERMINACIONES DE LOS NUMEROS PRIMOS EN 0123456789 EN PORCENTAJES - " ) f.write (str(terminacion1)) m.write( "\n-----------------------------------------------------------\n" ) m.write( "NUMEROS PRIMOS CUYA SUMA DE DIGITOS ES TAMBIEN NUMERO PRIMO - " ) m.write ("%d\n" % cuantossumas) m.write( "-----------------------------------------------------------" ) l.write( "-----------------------------------------------------------" ) f.write( "\n-----------------------------------------------------------" ) print cuenta, "... Numeros Primos Desde ",inicio," Hasta ",limite," ...\n" print capicua, "... Numeros Primos Capicua ...\n" print gemelos, "... Numeros Primos Gemelos ...\n" print izde, "... Numeros Primos Que Leidos De Drch A Izq Y Al Reves Son Primos ...\n" print cuantossumas,"... Numeros Primos Cuya Suma De Digitos Es Numero Primo Tambien ...\n" print divihechas, "... Numero De Divisiones Realizadas Para El Computo Total De Primos ...\n" print int(divihechas/restita), "... Divisiones Por Segundo Realizadas ...\n" print "Primos Mayores Que 2147483647 No Analizados Al Dar La Vuelta A Un Numero Primo Por Superar El Rango. "+str(nosepuede) print "\nTerminaciones De Los Primos En 0123456789\n" print terminacion print "\nPorcentajes De Terminaciones En 0123456789\n" print terminacion1 if porpantalla==2 and lombarda==1: f.write( "\nPROGRAMA CREADO POR M8AX PARA CALCULAR NUMEROS PRIMOS " ) f.write( "\n^MvIiIaX^ Corp 2006 " ) f.write( "\n-----------------------------------------------------------" ) f.close() q.close() l.close() m.close() if avisarmovil==1 and porpantalla==2: formas+=1 print "\n... Haciendo Llamadas Perdidas Para Avisar Del Fin De Los Calculos ..." telephone.dial(str(movil)) e32.ao_sleep(10) telephone.hang_up() e32.ao_sleep(5) telephone.dial(str(movil)) e32.ao_sleep(10) telephone.hang_up() e32.ao_sleep(5) telephone.dial(str(movil)) e32.ao_sleep(10) telephone.hang_up() e32.ao_sleep(5) mmsmodule.mms_send(unicode(str(movil)), unicode("Mensaje Numero ("+str(formas)+")"+" ... Proceso De Calculo De Primos Ha Finalzado ... PROGRAMA CREADO POR MARCOS OCHOA DIEZ. M8AX."),unicode("e:\\system\\apps\\python\\mviiiaxlogo.jpg")) print "\n... Mandando MMS Con Aviso De Finalizacion De Calculos ..." print "\n\n^MvIiIaX^ Corp. 2006" appuifw.note(u"¡¡¡ Guau !!! Ya Esta Todo El Trabajo Realizado :)", "info" )