Skip to content

Instantly share code, notes, and snippets.

@daiando
Created December 7, 2015 01:13
Show Gist options
  • Save daiando/75f68e5654285f707758 to your computer and use it in GitHub Desktop.
Save daiando/75f68e5654285f707758 to your computer and use it in GitHub Desktop.
Consider and arithmetico-geometric sequence where the nth term of the sequence is denoted by t(n)=n**2+1,n>0. In this challenge, your task is to complete the sum method which takes an integer n and returns the sum to the n terms of the series.
def sum_terms(n)
(1..n).reduce(0){|sum, i| sum + i**2 + 1}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment