- Code: Select all
(loop for x from 1 to 10
sum (* x x))
This returns 385, however, what I want it to do is get the sum from 1 to 10 (which is 55) and then do (* 55 55), which equals 3025. What I want it to do is (expt 55 2), but it must take the sum before it does the expt. The current code is taking the exponent of each and them summing the result.
I clearly would like to write:
- Code: Select all
(loop for x from 1 to 10
(expt (sum x) 2))
...but it does not work because 'sum' is part of the loop macro and not an actual function.
Btw, this is from Project Euler.
Any tips?