Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created June 22, 2016 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomcha/b2860384c2ce1a054c9809682d60f39a to your computer and use it in GitHub Desktop.
Save tomcha/b2860384c2ce1a054c9809682d60f39a to your computer and use it in GitHub Desktop.
Recursion1
list = [1, 2, 3, 4, 5, 6]
def sum(nums)
if nums.size == 0
0
else
n = nums.shift
n + sum(nums)
end
end
puts sum(list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment