[pyar] Devolver 2 valores generados por función yield

Damián Avila damianavila en gmail.com
Mar Oct 7 06:59:40 ART 2014


Más info: http://en.wikipedia.org/wiki/Approximations_of_%CF%80

es particularmente interesante...
http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula

2014-10-07 0:51 GMT-03:00 Mati Barriento <elmatibarriento en gmail.com>:

> >Pregunta al margen: de dónde salió el algoritmo?
>
> Lo hice una mañ......nah, lo encontre en stackoverflow {0}
> No lo entiendo y la verdad que no me puse a pensar pero me parecio mágico.
>
> Solucion final:
>
>     def make_pi():
>         q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
>         while True:
>             if 4 * q + r - t < m * t:
>                 yield m
>                 q, r, t, k, m, x = 10*q, 10*(r-m*t), t, k, (10*(3*q+r))//t
> -
> 10*m, x
>             else:
>                 q, r, t, k, m, x = q*k, (2*q+r)*x, t*x, k+1,
> (q*(7*k+2)+r*x)//(t*x), x+2
>
>    digitsArray = []
>    m = make_pi()
>    next(m) #gasta el primer digito.
>    for i in range(0,longer):
>       x,y = [next(m),next(m)] #consume 2 veces el generador
>       digitsArray.append(((x*10)+y))
>
>
> {0} http://stackoverflow.com/questions/9004789/1000-digits-of-pi-in-python
>
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>
> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
> Argentina - http://www.usla.org.ar
>



-- 
*Damián*
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20141007/80c40846/attachment.html>


More information about the pyar mailing list