Advertisement
brewersfan1976

range_bit_count.rb

Sep 25th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.41 KB | None | 0 0
  1. def rangeBitCount(a, b)
  2.     x = a
  3.     number = 0
  4.    
  5.     while (x <= b)
  6.           string = x.to_s(2)
  7.           y = 0
  8.          
  9.           while (y < string.length)
  10.                 if string[y] == '1' then
  11.                    number = number + 1
  12.                 end
  13.                
  14.                 y = y + 1
  15.           end
  16.              
  17.           x = x + 1
  18.     end
  19.        
  20.     return number
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement