Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def f(x, n=0) :
- head, tail = x
- if n<100 :
- return head + 1.0/(f(tail, n+1))
- return head
- x = [1]
- x.append(x)
- print f(x)
- def f2(n) :
- a,b = 1,1
- for i in range(n):
- b,a = a,a+b
- return a/float(b)
- print f2(100)
- def f3(x) :
- y = 1.0
- for i in range(100) :
- y = 0.5*(1+y + x/y)
- return y
- print f3(1.0)
- class RabbitPair(object) :
- def __init__(self) :
- self.age = 0
- def mate(self) :
- offspring = []
- if self.age > 0 :
- offspring.append(RabbitPair())
- self.age += 1
- return offspring
- populations = []
- rabbit_pairs = [RabbitPair()]
- for i in range(20) :
- new_rabbits = []
- for rabbit_pair in rabbit_pairs :
- new_rabbits += rabbit_pair.mate()
- rabbit_pairs += new_rabbits
- populations.append(len(rabbit_pairs))
- print populations[-1]/float(populations[-2])
- x = [False]
- a,b = 1,1
- for i in range(30) :
- new = [False for y in x if y]
- x = [True]*len(x) + new
- a,b = b,len(x)
- print b/float(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement