Created
March 3, 2013 16:35
-
-
Save noriaki/5076806 to your computer and use it in GitHub Desktop.
rubyでビット文字列から'1'の位置を求める ref: http://qiita.com/items/0726851e110e2e356791
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
"10100100110".reverse.split('1',-1).inject([]){|ret,i| ret << i.size + (ret.last.nil? ? 0 : ret.last + 1); ret }[0..-2] | |
# => [1, 2, 5, 8, 10] |
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
"10100100110".split('1',-1).inject([]){|ret,i| ret << i.size + (ret.last.nil? ? 0 : ret.last + 1); ret }[0..-2] | |
# => [0, 2, 5, 8, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment