""" 2048 核心算法 """
#零元素移植末尾
#[2,0,2,0] -->[2,2,0,0]
list_merge = [2,0,4,8]
def zer_to_end():
""" 從後向前,如果發現零元素,刪除並追加 :return: """
for i in range(-1,-len(list_merge)-1,-1):
if list_merge[i]==0:
del list_merge[i]
list_merge.append(0)
zer_to_end()
print(list_merge)