Advertisement
misingnoglic

Untitled

Jan 24th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1.  
  2. from fractions import *
  3. def realloop(n):
  4.     L=[[Fraction(1,1)]]
  5.     while n>1:
  6.         x=[]
  7.         for i in L[-1]:
  8.             x+=[Fraction(i.numerator+i.denominator,i.denominator),Fraction(i.numerator,i.numerator+i.denominator)]
  9.             L.append(x)
  10.         n=n-1
  11.     t=[]
  12.     for i in L:
  13.     t+=i
  14.     return t
  15.  
  16. def calkin(n):
  17.     L=[(1,1)]
  18.     yield L[0]
  19.     while n>1:
  20.         for i in L:
  21.             x=[]
  22.             yield (i[0]+i[1],i[1])
  23.             yield (i[0]+i[1],i[1])
  24.             L=[(x[0],x[1]+x[0]) for x in L]+[(x[0]+x[1],x[1]) for x in L]
  25.     n=n-1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement