Advertisement
febrezo

Estudio del sorteo de entradas para la Copa (ATHLETIC)

Apr 17th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.83 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. ##
  3. ##    Copyright 2012 Félix Brezo (febrezo @ www.felixbrezo.com)
  4. ##
  5. ##    This program is free software: you can redistribute it and/or modify
  6. ##    it under the terms of the GNU General Public License as published by
  7. ##    the Free Software Foundation, either version 3 of the License, or
  8. ##    (at your option) any later version.
  9. ##
  10. ##    Sira is distributed in the hope that it will be useful,
  11. ##    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ##    GNU General Public License for more details.
  14. ##
  15. ##    You should have received a copy of the GNU General Public License
  16. ##    along with pySorteo.  If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. import argparse
  19. from math import sqrt
  20.  
  21. print "Parseando argumentos..."
  22.  
  23. parser = argparse.ArgumentParser(description='Cálculo de las posibilidades de ganar en un sorteo de extracción de una bola en el que los agraciados serán el afortunado y los N-1 números siguientes.')
  24. parser.add_argument('boletos', metavar='N', type=int, nargs='+',
  25.                    help='lista de los números del sorteo')
  26. parser.add_argument('-e', '--entradas', metavar='NUM_ENTRADAS', required=True, help='el número de entradas que se sortean')
  27. parser.add_argument('-p', '--peticiones', metavar='NUM_PETICIONES', required=True, help='el número de peticiones enviadas al club')
  28.  
  29. args = parser.parse_args()
  30.  
  31. print "Arrancando procedimientos..."
  32.  
  33. # Diccionario que almacenará el número de veces que ha salido cada opción.
  34. reparto={}
  35.  
  36. if int(args.peticiones) < int(args.entradas):
  37.     print "Enhorabuena, hay entradas para todos."
  38.     # No hacemos nada más. ¿Qué queríais calcular?
  39. else:
  40.     valido = True
  41.     # Chequear que no hay ningún boleto superior al número de peticiones
  42.     for k in args.boletos:
  43.         if int(k)>int(args.peticiones):
  44.             valido=False
  45.             print "Se ha producido un error. El número de boleto "+str(k)+" es mayor que el número de peticiones ("+args.peticiones+")."
  46.             break  
  47.     if valido: 
  48.         #recorremos todas las opciones
  49.         for i in range(int(args.peticiones)):
  50.             entradas=0
  51.             for j in args.boletos:
  52.                 if ((i)+int(args.entradas)) < int(args.peticiones):
  53.                     if int(j-1)>=i and int(j-1) <(i+int(args.entradas)):
  54.                         entradas+=1
  55.                 else:
  56.                     # Volvemos al principio...
  57.                     if int(j-1)>=i:
  58.                         entradas+=1
  59.                     elif int(j-1) < ((i+int(args.entradas)) % int(args.peticiones)):
  60.                         entradas+=1
  61.             if entradas in reparto:
  62.                 reparto[entradas]+=1
  63.             else:
  64.                 reparto[entradas]=1
  65.         # Mostramos la infor
  66.         print "INFORMACIÓN"
  67.         print "-----------"
  68.         # Esto es culturilla... Gracias Wikipedia.
  69.         print "\t- Media: la media (aritmética) es la cantidad total de la variable distribuida a partes iguales entre cada observación."
  70.         print "\t- Varianza: la varianza representa la media aritmética de las desviaciones con respecto a la media que son elevadas al cuadrado."
  71.         print "\t- Desviación típica: la desviación típica es una medida (cuadrática) que informa de la media de distancias que tienen los datos respecto de su media aritmética, expresada en las mismas unidades que la variable."
  72.         print "\n"
  73.         print "Calculando estadísticos..."
  74.         print "\n"
  75.         suma=0
  76.         for i in reparto:
  77.             suma+=float(i)*reparto[i]
  78.         media = suma/float(args.peticiones)
  79.         print "\tMedia:\t\t"+str(round(media,3))+" entradas."
  80.         suma=0
  81.         for i in reparto:
  82.             suma+=float(i)**2*reparto[i]
  83.         varianza= suma/float(args.peticiones)-media**2
  84.         print "\tVarianza:\t"+str(round(varianza,3))
  85.         print "\tDesv. T.:\t"+str(round(sqrt(varianza),3))+" entradas."
  86.         print "\n"
  87.         print "ASIGNACIÓN ESTIMADA (%)"
  88.         print "-----------------------"
  89.         for i in reparto:
  90.             print "\tHay un "+ str(round(reparto[i]/float(args.peticiones)*100,3))+"% de posibilidades de llevarse justo "+str(i)+" entrada(s)."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement