import math
def f(x):
return math.sqrt(x)%1==0
print filter(f,range(1,101))
def f(x):
return math.sqrt(x)%1==0
print filter(f,range(1,101))
2016-03-12
def calc_prod(lst):
def lazy_prod():
def f(x, y):
return x * y
return reduce(f, lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_prod():
def f(x, y):
return x * y
return reduce(f, lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-03-10
def calc_prod(lst):
def poly():
num = 1
for n in lst:
num *= n
return num
return poly
f = calc_prod([1, 2, 3, 4])
print f()
def poly():
num = 1
for n in lst:
num *= n
return num
return poly
f = calc_prod([1, 2, 3, 4])
print f()
2016-03-10
import math
def is_sqr(x):
return x % math.sqrt(x) == 0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return x % math.sqrt(x) == 0
print filter(is_sqr, range(1, 101))
2016-03-10
def prod(x,y):
return x*y;
def calc_prod(lst):
def lazy_calc_prod():
return reduce(prod,lst)
return lazy_calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
return x*y;
def calc_prod(lst):
def lazy_calc_prod():
return reduce(prod,lst)
return lazy_calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-03-08
class Fib(object):
def __init__(self, num):
self.num = [0, 1]
for i in range(0, num - 2):
self.num.append(self.num[i] + self.num[i + 1])
def __len__(self):
return len(self.num)
def __str__(self):
return str(self.num)
f = Fib(10)
print (f)
def __init__(self, num):
self.num = [0, 1]
for i in range(0, num - 2):
self.num.append(self.num[i] + self.num[i + 1])
def __len__(self):
return len(self.num)
def __str__(self):
return str(self.num)
f = Fib(10)
print (f)
2016-03-07