Created
July 3, 2015 15:32
-
-
Save jraregris/d963084227cb7b238459 to your computer and use it in GitHub Desktop.
This file contains 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 digit_sum n | |
n > 9 ? n.to_s.chars.map{ |i| digit_sum(i.to_i) }.inject(:+) : n | |
end | |
def accumulative_sum n | |
(1..n).map{|i| digit_sum i}.inject(:+) | |
end | |
puts accumulative_sum 11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment