Created
September 26, 2016 11:24
-
-
Save suryart/d54d66d96a3cbe095ebee8b9ba3a6ee4 to your computer and use it in GitHub Desktop.
sort by binary 1 count then by digit value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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