# Using the Sum function square the sums of numbers

How do I use the Sum function for adding and squaring consecutive terms? It's an exercise from Wolfram Challenges.

I want to write my own function that uses the Sum function to get the sum of (1+2)^2 if the user inputs a two. Or if the user inputs a three, then ((1+2)^2+3)^2).

Don't tell me the answer! A hint would suffice for the sake of a learning experience.

Also what kind of math should I look at to understand the soul of the exercise??

update!

Last@FoldList[Plus, 1, {a}]^2

func[b_] := Last@FoldList[Plus, b, {a + 1}]^2

Nest[func, Last@FoldList[Plus, 1, {a}]^2, 2]

(1 + a + (1 + a + (1 + a)^2)^2)^2


I wanted that leftmost one to be a 2.

• I think Sum[] is not going to work. Use the functions Fold[] and Range[] instead. – Somos Apr 28 at 0:55
• Does the exercise actually require the use of Sum? – m_goldberg Apr 28 at 4:49
• @m_goldberg no the excercise does not require Sum. that was my first guess at solving it via wolfram language. however now i think fold or foldlist or nest is the way. – Jonathan Silverman Apr 28 at 4:56
• @Somos Thanks for your advice. I have made an update to my question using different functions. – Jonathan Silverman Apr 28 at 5:03

• Use Fold with two arguments, a pure function as its 1st argument and a list as its 2nd.
• The list should be generated by Range; e.g., Range[3] to get the result when func is given 3.