Вы находитесь на странице: 1из 14

UNIVERSIDAD NACIONAL DE INGENIERA

FACULTAD DE INGENIERA INDUSTRIAL Y


DE SISTEMAS

INTELIGENCIA ARTIFICIAL
PRIMER PRCTICA CALIFICADA (ST-414 V)

INTEGRANTES:
GIRALDO SALINAS, Lizbeth Carol
20081172F
lizbethgiraldo18@gmail.com

HUAMANI DIAZ, No Guillermo

Inteligencia Artificial
20104533J
noe.huamani.diaz@gmail.com

HERRERA COSAR, Jhonattan Alfonso


20101056F
jhonattan.hc@gmail.com

MALDONADO TRIGOSO, Tania Alcira


20102611C
taty2010ii@gmail.com

-II

Inteligencia Artificial

-II

Primera Prctica
1. Describir procedimiento para desarrollar un icono para
identificar carpetas del software Word, de 3 ejemplos de
su solucin

2. El nmero 153 citado en el Evangelio de San Juan, en la


ltima pesca, tiene una propiedad muy interesante: si se
eleva al cubo cada dgito la suma de ellos es 153.
Desarrollar un programa en Python que indique en cuantos
ciclos un nmero impar converge en 153. Intente graficar
varios nmeros y calcule el mayor nmero que se puede
calcular. Haga una presentacin en Word
SOLUCION 2:
PPTs Impresas y tambin se encuentra en CD.

Inteligencia Artificial

-II

Inteligencia Artificial

Un mayor detalle se mostrar en las presentacin de Power Point.

-II

Inteligencia Artificial

-II

3. Escriba y pruebe un programa en Python para leer todas


las jugadas de la Tinka.
SOLUCION 3
import sys
from random import randint
BOLILLA_MINIMA = 1
BOLILLA_MAXIMA = 45
if len(sys.argv) != 2:
print "Uso correcto: %s <numero de jugadas> " % sys.argv[0]
sys.exit(1)
try:
num_jugadas = int(sys.argv[1])
except ValueError:
print u"El nmero de jugadas debe ser entero"
sys.exit(1)
if num_jugadas < 0:
print u"El nmero de jugadas debe ser un entero positivo"
sys.exit(1)
lista_jugadas = []
# Generar todas las jugadas
while len(lista_jugadas) < num_jugadas:
# Generar una jugada
jugada = []
while len(jugada)<7:
bolilla = randint(BOLILLA_MINIMA, BOLILLA_MAXIMA)
if bolilla not in jugada:
jugada.append(bolilla)
jugada = sorted(jugada)
# Si la jugada generada no exista ya en las jugadas aceptadas
if jugada not in lista_jugadas:
lista_jugadas.append(jugada)
# Imprimir jugadas
for jugada in lista_jugadas:
bolillas_como_cadena = []
for bolilla in jugada:
bolillas_como_cadena.append(str(bolilla))
print "-".join(bolillas_como_cadena)
#print "-".join([str(b) for b in jugada])

Inteligencia Artificial

-II

4. Con la Base de Datos de todas las jugadas de la TINKA


a) Determine si se ha repetido 3 nmeros consecutivos, empezando por las
columnas: 1, 2, 3, 4.
b) Cuntas veces se han repetido 2, 3, y 4 nmeros en los sorteos?
SOLUCION 4
a)
import os
import sys
from datetime import datetime, date
historico=[0]*45
todo=[]
def iniciar():
os.system(['clear','cls'][os.name == 'nt'])
a=raw_input("Elegir una opcion:\n 1.Ingresar resultado de la Tinka\n 2.Mostrar frecuencia
de los numeros\n
3.Mostrar frecuencia de los numeros en los n sorteos anteriores\n
4.Averigue si sus numeros han sido ganadores\n 5.Salir\n
Ingrese su opcion: ")
while a<'1' or a>'5':
os.system(['clear','cls'][os.name == 'nt'])
a=raw_input("Elegir una opcion:\n
1.Ingresar resultado de la Tinka\n
2.Mostrar
frecuencia de los numeros\n 3.Mostrar frecuencia de los numeros en los n sorteos anteriores\n
4.Averigue si sus numeros han sido ganadores\n 5.Salir\n
Ingrese su opcion: ")
opcion = int(a)
print opcion
if opcion == 1:
opcion1()
elif opcion == 2:
opcion2()
elif opcion == 3:
opcion3()
elif opcion == 4:
opcion4()
elif opcion == 5:
sys.exit

def agregar(n):
historico[n-1]=historico[n-1]+1
def valnum(m):
if not m.isdigit():
return False
elif int(m)>45 or int(m)<0:
return False
return True
def opcion1():

Inteligencia Artificial

-II

os.system(['clear','cls'][os.name == 'nt'])
print '=====================OPCION 1====================='
nums=raw_input("\nIngrese el numero de sorteo:")
while not nums.isdigit():
nums=raw_input("Ingrese el numero de sorteo:")
num1=raw_input("1er numero:")
while not valnum(num1):
num1=raw_input("1er numero:")
agregar(int(num1))
num2=raw_input("2do numero:")
while not valnum(num2):
num2=raw_input("2do numero:")
agregar(int(num2))
num3=raw_input("3er numero:")
while not valnum(num3):
num3=raw_input("3er numero:")
agregar(int(num3))
num4=raw_input("4to numero:")
while not valnum(num4):
num4=raw_input("4to numero:")
agregar(int(num4))
num5=raw_input("5to numero:")
while not valnum(num5):
num5=raw_input("5to numero:")
agregar(int(num5))
num6=raw_input("6to numero:")
while not valnum(num6):
num6=raw_input("6to numero:")
agregar(int(num6))
numy=raw_input("Ingrese el numero de la yapa (si no hubo yapa en este sorteo, ingrese 0: ")
while not valnum(numy):
numy=raw_input("Ingrese el numero de la yapa (si no hubo yapa en este sorteo, ingrese 0:
")
array=[nums,
datetime.today(),int(num1),int(num2),int(num3),int(num4),int(num5),int(num6),int(numy)]
todo.append(array)
print 'Se registro correctamente el resultado'
xxx=raw_input()
iniciar()
def opcion2():
os.system(['clear','cls'][os.name == 'nt'])
print '=====================OPCION 2=====================\n'
for i in range(len(historico)):
print 'Numero',i+1,historico[i]
xxx=raw_input()
iniciar()
def opcion3():
os.system(['clear','cls'][os.name == 'nt'])
print '=====================OPCION 3====================='
ns=raw_input("\nIngrese el numero de sorteos a considerar en la busqueda:")
while not ns.isdigit():
ns=raw_input("Ingrese el numero de sorteos a considerar en la busqueda:")
temp = [0]*45
for j in range(len(todo)-int(ns),len(todo)):
pcom = todo[j]
temp[pcom[2]-1]=temp[pcom[2]-1]+1
temp[pcom[3]-1]=temp[pcom[3]-1]+1

Inteligencia Artificial

-II

temp[pcom[4]-1]=temp[pcom[4]-1]+1
temp[pcom[5]-1]=temp[pcom[5]-1]+1
temp[pcom[6]-1]=temp[pcom[6]-1]+1
temp[pcom[7]-1]=temp[pcom[7]-1]+1
print ''
for k in range(len(temp)):
print 'Numero',k+1,temp[k]
xxx=raw_input()
iniciar()
def opcion4():
os.system(['clear','cls'][os.name == 'nt'])
print '=====================OPCION 4=====================\n'
print 'Ingrese sus 6 numeros de la suerte y averigue si ya han sido ganadores\n'
temp=[]
num1=raw_input("1er numero:")
while not valnum(num1):
num1=raw_input("1er numero:")
temp.append(int(num1))
num2=raw_input("2do numero:")
while not valnum(num2):
num2=raw_input("2do numero:")
temp.append(int(num2))
num3=raw_input("3er numero:")
while not valnum(num3):
num3=raw_input("3er numero:")
temp.append(int(num3))
num4=raw_input("4to numero:")
while not valnum(num4):
num4=raw_input("4to numero:")
temp.append(int(num4))
num5=raw_input("5to numero:")
while not valnum(num5):
num5=raw_input("5to numero:")
temp.append(int(num5))
num6=raw_input("6to numero:")
while not valnum(num6):
num6=raw_input("6to numero:")
temp.append(int(num6))
temp.sort()
idxenc=-1
for plop in range(len(todo)):
sorteo=todo[plop]
seq=sorteo[2:8]
seq.sort()
flag2=True
for idx in range(0,5):
if temp[idx] == seq[idx]:
continue
else:
flag2=False

Inteligencia Artificial

-II

break
if flag2:
idxenc=plop
break
if idxenc == -1:
print 'No se encontro ningun resultado con los numeros ingresados'
else:
qui=todo[idxenc]
num=qui[0]
fecha=qui[1]
print 'Los numeros fueron ganadores en el sorteo',num,'el',fecha.strftime("%d/%m/%y")
xxx=raw_input()
iniciar()
for resultado in todo:
agregar(resultado[2])
agregar(resultado[3])
agregar(resultado[4])
agregar(resultado[5])
agregar(resultado[6])
agregar(resultado[7])
iniciar()

b)
import os
import sys
from datetime import datetime, date
historico=[0]*45
todo=[]
def iniciar():
os.system(['clear','cls'][os.name == 'nt'])
a=raw_input("Elegir una opcion:\n
1.Ingresar resultado de la Tinka\n
2.Mostrar
frecuencia de los numeros\n
3.Mostrar frecuencia de los numeros en los n sorteos
anteriores\n 4.Averigue si sus numeros han sido ganadores\n 5.Salir\n
Ingrese su
opcion: ")
while a<'1' or a>'5':
os.system(['clear','cls'][os.name == 'nt'])
a=raw_input("Elegir una opcion:\n 1.Ingresar resultado de la Tinka\n 2.Mostrar
frecuencia de los numeros\n
3.Mostrar frecuencia de los numeros en los n sorteos
anteriores\n 4.Averigue si sus numeros han sido ganadores\n 5.Salir\n
Ingrese su
opcion: ")
opcion = int(a)
print opcion

10

Inteligencia Artificial

-II

if opcion == 1:
opcion1()
elif opcion == 2:
opcion2()
elif opcion == 3:
opcion3()
elif opcion == 4:
opcion4()
elif opcion == 5:
sys.exit

def agregar(n):
historico[n-1]=historico[n-1]+1
def valnum(m):
if not m.isdigit():
return False
elif int(m)>45 or int(m)<0:
return False
return True
def opcion1():
os.system(['clear','cls'][os.name == 'nt'])
print '=====================OPCION 1====================='
nums=raw_input("\nIngrese el numero de sorteo:")
while not nums.isdigit():
nums=raw_input("Ingrese el numero de sorteo:")
num1=raw_input("1er numero:")
while not valnum(num1):
num1=raw_input("1er numero:")
agregar(int(num1))
num2=raw_input("2do numero:")
while not valnum(num2):
num2=raw_input("2do numero:")
agregar(int(num2))
num3=raw_input("3er numero:")
while not valnum(num3):
num3=raw_input("3er numero:")
agregar(int(num3))
num4=raw_input("4to numero:")
while not valnum(num4):
num4=raw_input("4to numero:")
agregar(int(num4))
num5=raw_input("5to numero:")
while not valnum(num5):
num5=raw_input("5to numero:")
agregar(int(num5))
num6=raw_input("6to numero:")
while not valnum(num6):
num6=raw_input("6to numero:")
agregar(int(num6))
numy=raw_input("Ingrese el numero de la yapa (si no hubo yapa en este sorteo, ingrese
0: ")
while not valnum(numy):

11

Inteligencia Artificial

-II

numy=raw_input("Ingrese el numero de la yapa (si no hubo yapa en este sorteo,


ingrese 0: ")
array=[nums,
datetime.today(),int(num1),int(num2),int(num3),int(num4),int(num5),int(num6),int(numy)]
todo.append(array)
print 'Se registro correctamente el resultado'
xxx=raw_input()
iniciar()
def opcion2():
os.system(['clear','cls'][os.name == 'nt'])
print '=====================OPCION 2=====================\n'
for i in range(len(historico)):
print 'Numero',i+1,historico[i]
xxx=raw_input()
iniciar()
def opcion3():
os.system(['clear','cls'][os.name == 'nt'])
print '=====================OPCION 3====================='
ns=raw_input("\nIngrese el numero de sorteos a considerar en la busqueda:")
while not ns.isdigit():
ns=raw_input("Ingrese el numero de sorteos a considerar en la busqueda:")
temp = [0]*45
for j in range(len(todo)-int(ns),len(todo)):
pcom = todo[j]
temp[pcom[2]-1]=temp[pcom[2]-1]+1
temp[pcom[3]-1]=temp[pcom[3]-1]+1
temp[pcom[4]-1]=temp[pcom[4]-1]+1
temp[pcom[5]-1]=temp[pcom[5]-1]+1
temp[pcom[6]-1]=temp[pcom[6]-1]+1
temp[pcom[7]-1]=temp[pcom[7]-1]+1
print ''
for k in range(len(temp)):
print 'Numero',k+1,temp[k]
xxx=raw_input()
iniciar()
def opcion4():
os.system(['clear','cls'][os.name == 'nt'])
print '=====================OPCION 4=====================\n'
print 'Ingrese sus 6 numeros de la suerte y averigue si ya han sido ganadores\n'
temp=[]
num1=raw_input("1er numero:")
while not valnum(num1):
num1=raw_input("1er numero:")
temp.append(int(num1))
num2=raw_input("2do numero:")
while not valnum(num2):
num2=raw_input("2do numero:")
temp.append(int(num2))
num3=raw_input("3er numero:")
while not valnum(num3):
num3=raw_input("3er numero:")
temp.append(int(num3))

12

Inteligencia Artificial

-II

num4=raw_input("4to numero:")
while not valnum(num4):
num4=raw_input("4to numero:")
temp.append(int(num4))
num5=raw_input("5to numero:")
while not valnum(num5):
num5=raw_input("5to numero:")
temp.append(int(num5))
num6=raw_input("6to numero:")
while not valnum(num6):
num6=raw_input("6to numero:")
temp.append(int(num6))
temp.sort()
idxenc=-1
for plop in range(len(todo)):
sorteo=todo[plop]
seq=sorteo[2:8]
seq.sort()
flag2=True
for idx in range(0,5):
if temp[idx] == seq[idx]:
continue
else:
flag2=False
break
if flag2:
idxenc=plop
break
if idxenc == -1:
print 'No se encontro ningun resultado con los numeros ingresados'
else:
qui=todo[idxenc]
num=qui[0]
fecha=qui[1]
print 'Los numeros fueron ganadores en el sorteo',num,'el',fecha.strftime("%d/%m/%y")
xxx=raw_input()
iniciar()
for resultado in todo:
agregar(resultado[2])
agregar(resultado[3])
agregar(resultado[4])
agregar(resultado[5])
agregar(resultado[6])
agregar(resultado[7])
iniciar()
La imagen que demuestra el resultado es:

13

Inteligencia Artificial

-II

Store
Procedure

Frecuencia y
Probabilidad
de Nmeros

Frecuencia y
Probabilidad
de Nmeros

14

Вам также может понравиться