Skip to content

Instantly share code, notes, and snippets.

@neilmiddleton
Created February 22, 2013 18:31
Show Gist options
  • Save neilmiddleton/5015528 to your computer and use it in GitHub Desktop.
Save neilmiddleton/5015528 to your computer and use it in GitHub Desktop.
Nik's problem
def heavy_decimal_count(a,b)
heavy = []
(a..b).collect do |number|
chars = number.to_s.split('').collect{|x| x.to_i}
heavy << number if (get_avg(chars) > 7)
end
heavy
end
def get_avg(arr)
arr.inject{|sum,x| sum + x }.to_f / arr.size
end
puts heavy_decimal_count(8675,8689)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment