Skip to content

Instantly share code, notes, and snippets.

@suryart
Created September 26, 2016 11:24
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 suryart/d54d66d96a3cbe095ebee8b9ba3a6ee4 to your computer and use it in GitHub Desktop.
Save suryart/d54d66d96a3cbe095ebee8b9ba3a6ee4 to your computer and use it in GitHub Desktop.
sort by binary 1 count then by digit value
# sort by binary 1 count then by digit value
a.sort_by{ |v1| [v1.to_s(2).split('').count('1'), v1] }.reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment