Input: list of weights.
Output: A number representing the smallest possible weight difference.
for exmaple:
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"
this is my code:
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))))
but the code is not working, please help me! thank you very much!
source share