Skip to content

Instantly share code, notes, and snippets.

@gabriel-tincu
Created May 16, 2017 15:48
Show Gist options
  • Save gabriel-tincu/749752f09a4eebbd3ba19c50230a11a4 to your computer and use it in GitHub Desktop.
Save gabriel-tincu/749752f09a4eebbd3ba19c50230a11a4 to your computer and use it in GitHub Desktop.
def split_list(l):
results = []
for i in range(1, len(l)):
results.append((l[:i], l[i:]))
return results
def abs_diff(a):
l, r = a
return abs((sum(l)) - sum(r))
def optimal_split(l):
return min(split_list(l), key=abs_diff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment