#!/usr/bin/env python
#求两序列的和最小差值序列
def meanList(sorted_list):
global big_list
global small_list
if not sorted_list:
return [],[]
#print("small = {0}\tbig={1}".format(sorted_list[-2],sorted_list[-1]))
meanList(sorted_list[:-2])
if(sum(big_list) < sum(small_list)):
big_list.append(sorted_list[-1])
small_list.append(sorted_list[-2])
else:
big_list.append(sorted_list[-2])
small_list.append(sorted_list[-1])
#if sum(big_list) < sum(small_list):
# tmp = small_list
# small_list = big_list
# big_list = tmp
#sorted_list = [1,2,3,4,5,6,7,8,9,10]
test_list = [12312, 12311, 232, 555, 3550, 29, 3, 2, 1, 566,6434,34]
if len(test_list) % 2:
test_list.append(0)
test_list.sort()
#sorted_list.reverse()
#print(test_list)
big_list = []
small_list = []
meanList(test_list)
print(big_list)
print("sum of big list is\t",sum(big_list))
print(small_list)
print("sum of small list is\t",sum(small_list))
print(str(sum(big_list)) + "-" + str(sum(small_list)) + "=" + str(sum(big_list) - sum(small_list) ) )
|