Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
Created July 1, 2010 07:33
Show Gist options
  • Save shihongzhi/459685 to your computer and use it in GitHub Desktop.
Save shihongzhi/459685 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
#coding=utf-8
def mean(sorted_list):
if not sorted_list:
return ([],[])
big=sorted_list[-1]
small=sorted_list[-2]
big_list,small_list=mean(sorted_list[:-2])
big_list.append(small)
small_list.append(big)
if sum(big_list)>sum(small_list):
return (big_list,small_list)
else:
return (small_list,big_list)
if __name__=='__main__':
tests=[[1,2,3,4,5,6,700,800],[10001,10000,100,90,50,1],range(1,11)]
for test in tests:
test.sort()
l1,l2=mean(test)
print l1,l2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment