Skip to content

Instantly share code, notes, and snippets.

@neilmiddleton
Created February 22, 2013 18:35
Show Gist options
  • Save neilmiddleton/5015552 to your computer and use it in GitHub Desktop.
Save neilmiddleton/5015552 to your computer and use it in GitHub Desktop.
Nik's problem, but better
def heavy_decimal_count(a,b)
(a..b).select do |number|
chars = number.to_s.split('').collect{|x| x.to_i}
get_avg(chars) > 7
end
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