Skip to content

Instantly share code, notes, and snippets.

@lwander
Created October 21, 2015 13:53
Show Gist options
  • Save lwander/42e2f4fd8cb4832ee1e9 to your computer and use it in GitHub Desktop.
Save lwander/42e2f4fd8cb4832ee1e9 to your computer and use it in GitHub Desktop.
easy_partition
easy_partition(keys, T)
B = []
A = []
B_s = 0
A_s = 0
keys = sort(keys)
while len(keys) > 0
k = pop_biggest(keys)
if B_s + k > T:
if A_s + k > T:
return ([], [])
else:
A.push(k)
A_s += k
else:
B.push(k)
B_s += k
return (A, B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment