Skip to content

Instantly share code, notes, and snippets.

@jraregris
Created July 3, 2015 15:32
Show Gist options
  • Save jraregris/d963084227cb7b238459 to your computer and use it in GitHub Desktop.
Save jraregris/d963084227cb7b238459 to your computer and use it in GitHub Desktop.
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