Skip to content

Instantly share code, notes, and snippets.

@luisfredgs
Forked from fmasanori/facebook_hackaton.py
Last active August 29, 2015 14:16
Show Gist options
  • Save luisfredgs/b2d3037704ae94b1a160 to your computer and use it in GitHub Desktop.
Save luisfredgs/b2d3037704ae94b1a160 to your computer and use it in GitHub Desktop.
def hack1(n, k):
def f(s):
return s.count('1')
binaries = []
for x in range(2**n):
binaries.append(bin(x))
binaries.sort(key=f, reverse = True)
return binaries[k - 1]
def hack(n, k):
return sorted([bin(x) for x in range(2**n)],
key=lambda s: s.count('1'),
reverse = True)[k-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment