Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. from fractions import Fraction
  2. from math import sqrt
  3.  
  4. def ramanujan(k): #jakis syf do przyblizenia pi
  5.     pi = Fraction(1,1)
  6.     fact1 = fact2 = Fraction(1,1)
  7.     for i in range(k):
  8.         fact1 *= 4*k
  9.         fact2 *= k
  10.         pi += Fraction(fact1*(1103+26390*k),((fact2)**4)*(396**(4*k)))
  11.     pi *= ((2*sqrt(2)) / 9801)
  12.     pi **= (-1)
  13.     pi -= 10**10*Fraction(32,1000000000)
  14.     return str(int(10**100*pi))
  15.  
  16. p = ramanujan(1)
  17. tadzio = open('tadek.txt',encoding='utf-8').read().split()
  18. fragment = topowy =  ''
  19. poczatek = 0
  20. brama = True
  21. j = 0
  22. iteracje = 0
  23. for i, slowo in enumerate(tadzio, poczatek):
  24.     iteracje += 1
  25.     d = len(slowo)
  26.     if d == int(p[j]):
  27.         j += 1
  28.         fragment += (' ' + slowo)
  29.         if d == 3:
  30.             if brama:
  31.                 if i != poczatek:
  32.                     #print(poczatek)
  33.                     brama = False
  34.                     poczatek = i
  35.     elif d == 10:
  36.         if d == int(p[j]):
  37.             j += 1
  38.             fragment += (' ' + slowo)
  39.     else:
  40.         i = poczatek
  41.         j = 0
  42.         brama = True
  43.         if len(fragment) > len(topowy):
  44.             topowy = fragment
  45.         fragment = ''
  46. print(topowy, iteracje, len(tadzio))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement