Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Loading Cargo by pawel1337
import math
def binary(n, l):
out = ""
while n!=0:
if (n%2 == 1):
out = '1' + out
else:
out = '0' + out
n //= 2
if (len(out)>l):
return 'nope'
while (len(out) < l):
out = '0' + out
return out
def total(data, number):
t = 0
counter = 0
for i in number:
if i == '1':
t += data[counter]
counter += 1
return t
def checkio(data):
sum = 0
l = len(data)
for i in data:
sum += i
min = 1000000000
done = False
n = 0
while not done:
current = binary(n, l)
if current != 'nope':
x = total(data, current)
if (math.fabs((sum - x)-x) < min):
min = math.fabs((sum - x)-x)
else:
done = True
n += 1
return min
print(checkio([10, 10]))
Nov. 5, 2016