输入数据:权重列表。如何计算代表最低可能重量差异的数字
输出数据:代表最小可能重量差的数字。
为〔实施例:
assert checkio([10, 10]) == 0, "1st example"
assert checkio([10]) == 10, "2nd example"
assert checkio([5, 8, 13, 27, 14]) == 3, "3rd example"
assert checkio([5, 5, 6, 5]) == 1, "4th example"
assert checkio([12, 30, 30, 32, 42, 49]) == 9, "5th example"
assert checkio([1, 1, 1, 3]) == 0, "6th example"
这是我的代码:
import random
def checkio(data):
for i in range(1,k):
half_sum = (reduce(lambda x,y:x+y,data))/2
k = len(data)
return min(lambda a:a >= half_sum,map(sum(random.sample(data,i))))
但代码不能正常工作,请帮帮我!非常感谢!
函数不应该是'min'的第一个参数。 –
你的意思是两个重量之间可能的最小差异? – arshajii
@LevLevitsky谢谢!我试图修复它.. – cedrichu