Skip to content

Instantly share code, notes, and snippets.

@douglasdrumond
Created May 27, 2013 07:45
Show Gist options
  • Save douglasdrumond/5655686 to your computer and use it in GitHub Desktop.
Save douglasdrumond/5655686 to your computer and use it in GitHub Desktop.
n, k = gets.split.map(&:to_i)
processed = (0...1<<n).to_a.sort_by { |x| [x.to_s(2).count("1"), x] }
puts processed[k-1].to_s(2).rjust(n, '0')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment