Skip to content

Instantly share code, notes, and snippets.

@lwander
Created October 21, 2015 13:53

Revisions

  1. lwander created this gist Oct 21, 2015.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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)