fork download
  1. def binary(n)
  2. n.to_s(2).reverse.chars.each_with_index.map {|c,i| 2 ** i if c.to_i == 1}.compact
  3. end
  4.  
  5. 1.upto (100_000) { |n| binary n }
Success #stdin #stdout 1.48s 4892KB
stdin
Standard input is empty
stdout
Standard output is empty