Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Loading Cargo by sleepyone
from itertools import combinations
import math
def checkio(stones):
'''
minimal possible weight difference between stone piles
'''
subsets = []
s = sum(stones)
for i in range(len(stones)):
subsets = subsets + list(map(sum,combinations(stones, i)))
return min(map(lambda y: s - 2*y if s > 2*y else 2*y - s, subsets))
if __name__ == '__main__':
assert checkio([10,10]) == 0, 'First, with equal weights'
assert checkio([10]) == 10, 'Second, with a single stone'
assert checkio([5, 8, 13, 27, 14]) == 3, 'Third'
assert checkio([5,5,6,5]) == 1, 'Fourth'
assert checkio([12, 30, 30, 32, 42, 49]) == 9, 'Fifth'
assert checkio([1, 1, 1, 3]) == 0, "Six, don't forget - you can hold different quantity of parts"
print ('All is ok')
Oct. 28, 2012