Created
February 22, 2013 18:35
-
-
Save neilmiddleton/5015552 to your computer and use it in GitHub Desktop.
Nik's problem, but better
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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