看來我的英文真是菜到爆,應該只有國小程度吧...XD,沒想到連考黑板題也寫的七七八八,真該撞牆好了.看來我還是沒有那個命阿.
題目:
> 5
print out 出底下 answer.
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
底下用 @ python
# \* breif sort + inverse
# * retrun [] */
def new_sort_0(i):
new_sort_0 = []
new_sort_1 = []
for j in range(i):
new_sort_0.insert(j,pow(2,j))
new_sort_0.insert(i,pow(2,i))
new_sort_1 = new_sort_0[:]
new_sort_1.reverse()
new_sort_1.pop(0)
return new_sort_0 + new_sort_1
# \* brief leaf 2 middle
# * return [] */
def new_sort_1(i):
new_sort = []
# @ leaf
for j in range(i):
new_sort.insert(j ,pow(2,j))
new_sort.insert(-(j+1),pow(2,j))
# @ middle
new_sort.insert(i,pow(2,i))
return new_sort
# @ run test
for i in range(5):
a = new_sort_1(i)
b = new_sort_0(i)
print a, b
del a, b
command:
回覆刪除list = [ pow(2,i) for i in range(5) ] + [ pow(2,j) for j in range(3,-1,-1) ]
results:
[1, 2, 4, 8, 16, 8, 4, 2, 1]