Skip to content

Instantly share code, notes, and snippets.

@ulope
Created July 5, 2012 19:35
Show Gist options
  • Save ulope/3055943 to your computer and use it in GitHub Desktop.
Save ulope/3055943 to your computer and use it in GitHub Desktop.
import fileinput
import itertools
def get_diff(teams):
a = teams[:len(teams)/2]
b = teams[len(teams)/2:]
# print "comp", a, b
return abs(sum(a) - sum(b))
def main():
for i, line in enumerate(fileinput.input()):
if i == 0:
# useless bs
continue
else:
proc_line = line.split()
num_players = int(proc_line[0])
skills = map(int, proc_line[1:])
combinations = list(itertools.permutations(skills, num_players))
print min(map(get_diff, combinations))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment