Here is the code:
def count_ones(number, num_bits)
(0...num_bits).inject(0) { |total, shift| total + (number >> shift & 1) }
end
puts (0...gets.to_i).map do
start, finish = gets.split.map(&:to_i)
(start..finish).inject(0) { |total, number| total + count_ones(number, 32) }
end
If I input 3, I would expect to be able to input 3 more times. Instead it prints out an enumerable object..
But.. if I do this, and input 3 :
puts (0...gets.to_i).map { |i| i }
I get the result I'm expecting: 0 1 2
How can I reconcile these contradictory behaviors with one and other?