1. 编写一个函数求 Fibonacci 数列第 n 项。
def judge(n):
return True if not (n>>1)&n else False
def remap(func,src):
def combin(l, n):
'''
>>> combin(list(range(1, 5)), 3)
[[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
>>> list(map(lambda x: ''.join(x), combin("world", 3))))
['wor', 'wol', 'wod', 'wrl', 'wrd', 'wld', 'orl', 'ord', 'old', rld']
'''
pass
def comb(l,n):
res=[]
tmp=[0]*n
def fill_tmp(start=0,count=0):
if count==n :
res.append(copy.copy(tmp))
return
fill_tmp(j+1,count+1)
fill_tmp()
fib=lambda n,x=0,y=1:x if n <2 else fib(n-1,y,x+y)
def judge(n):
return True if not (n>>1)&n else False
judge=lambda n:True if not (n>>1)&n else False
def remap(func,src):
return reduce(lambda x,y:x+[func(y)],src,[])
C(13,6) =1716
def combin(l, n):
'''
>>> combin(list(range(1, 5)), 3)
[[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
>>> list(map(lambda x: ''.join(x), combin("world", 3))))
['wor', 'wol', 'wod', 'wrl', 'wrd', 'wld', 'orl', 'ord', 'old', rld']
'''
pass
def comb(l,n):
res=[]
tmp=[0]*n
def fill_tmp(start=0,count=0):
if count==n :
res.append(copy.copy(tmp))
return
for j in xrange(start,len(l)):
if count <= n-1:
tmp[count]=l[j]fill_tmp(j+1,count+1)
fill_tmp()
return res;