I want to sum the squares for a given number N from 1 without using Multiplication. Is it possible?
|
Figuring out what the following snippet does is left as an exercise for the reader:
|
|||||
|
|
A Mathematica minded answer:
So:
|
|||||||||||||
|
|
Someone certainly had to write this recursive one:
|
|||
|
|
|
Try this :
to check how it works, e.g. :
There is also a purely symbolic approach, e.g. : $\quad n^2$
Note :
Test We added Verde's approach (
Conclusion Symbolic computations are especially recommended |
||||
|
|
|
Yes, it is possible. Since multiplication of positive integers is repeated addition, we can repeatedly add instead of multiply:
|
|||
|
|
|
An oddball one using a recursive, memoizing function for the square.
It's not something I would directly use for such a goal, but you asked for something without explicit multiplications and you got it. Alternatively, if we don't interpret
would fit the requirements too. |
|||
|
|
I think this exercise is somewhat of a Rorschach test… I don't know what the above says about me, though :) |
|||||||||||
|
|
I'll join the bandwagon with
|
|||||||||||
|
|
If exponentiation is allowed, how about this?
Explanation
|
||||
|
|
|
You can sum the diagonal. However, that might be slowest procedure of all.
|
|||||||||
|




n = 10;Sum[i^2, {i, 1, n}]orTotal@Table[i^2, {i, 1, n}]. – PlatoManiac Sep 5 '12 at 9:38Forloop.. – PlatoManiac Sep 5 '12 at 9:57