Skip to content

Instantly share code, notes, and snippets.

@douglasdrumond
Created May 27, 2013 07:45
Show Gist options
  • Save douglasdrumond/5655684 to your computer and use it in GitHub Desktop.
Save douglasdrumond/5655684 to your computer and use it in GitHub Desktop.
n,k = map(int, raw_input().split())
processed = sorted(range(1<<n), cmp=lambda a,b: cmp(bin(a).count("1"), bin(b).count("1")) if cmp(bin(a).count("1"), bin(b).count("1")) else cmp(a,b))
print bin(processed[k - 1])[2:].zfill(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment