Created
December 7, 2015 01:13
-
-
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.
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 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