Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2 つの 1 の間のすべての 0 を抽出し、それらを 2 進数からグループ化したいと考えています。これまでやってきたのは、
529.to_s(2).scan(/1(0+)1/)
2つの要素が必要ですが、出力は1つの要素のみの配列です。あれは
529 => binary => 1000010001 ["0000","000"]
529.to_s(2).scan(/(?<=1)0+(?=1)/) # => ["0000", "000"]
これはどのように ?
a = 529.to_s(2).split("1") a.delete("") a # => ["0000", "000"]