Skip to content

Instantly share code, notes, and snippets.

@christianroman
Last active December 29, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianroman/7636308 to your computer and use it in GitHub Desktop.
Save christianroman/7636308 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup: Basketball Game
lines, w, out, l, c = [line.strip() for line in open('basketball_game.txt')], ' ', '', 1, 0
while l < lines.__len__():
s = lines[l].split(w)
tp, rt, ts = int(s[0]), int(s[1]), int(s[2])
tmp = lines[slice(l + 1, l + tp + 1)]
pl = [{'name': i.split(w)[0], 'shot': i.split(w)[1], 'height': i.split(w)[2]} for i in tmp]
srtd = sorted(pl, key=lambda k: (k['shot'], k['height']), reverse=True)
t1, t2 = srtd[0:][::2], srtd[1:][::2]
nt1 = t1[-rt % len(t1):] + t1[:-rt % len(t1)]
nt2 = t2[-rt % len(t2):] + t2[:-rt % len(t2)]
r = w.join(sorted([x['name'] for x in nt1[:ts]] + [x['name'] for x in nt2[:ts]]))
l, c = l + tp + 1, c + 1
out += 'Case #{0}: {1}\n'.format(c, r)
with open ('output', 'w') as f: f.write (out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment