Skip to content
loading...

re: Daily Challenge #152 - Strongest Number in an Interval VIEW POST

FULL DISCUSSION
 

Ruby

def get_strength(num)
  strength=0
  while !num.odd?
      num /= 2
      strength += 1
  end
  strength
end

def get_num_of_lowest_strength(nums)
  strength=Array.new
  nums.each do 
    |x| 
    strength.push [x, get_strength(x)]
  end  
  strength.sort_by{|k,v| [v,k]}.reverse
end

nums=[5..10,48..56,129..193]

nums.each do
  |num|
  x= get_num_of_lowest_strength(num)
  p x[0][0]
end
code of conduct - report abuse