For those who didn't know, Sigma is a Greek letter which is heavily used in mathematics as the summation sign. Given a string representing an expression depending on \$k\$ that we will denote \$E(k)\$, compute the sum of the results for \$E(k)\$, for each \$k\in\{1,2,3,4,5\}\$. Concisely, you should find \$S\$ such that:
$$S=\sum^5_{k=1}E(k)$$
An example of an expression: \$E(k)=\frac k 2 + k^2\$
Specs
- You are guaranteed:
- that the expression is valid, so it contains no errors, and that it's dependent of the syntax chosen (e.g: if you only support
2*k
, there will be no2k
) - to only have defined values amongst your results, so no values like
1/0
,inf
ornan
will appear
- that the expression is valid, so it contains no errors, and that it's dependent of the syntax chosen (e.g: if you only support
- You can assume that the expression above is fitting the limits of the programming language of your choice, so it won't result in overflows or any other limit-related errors
- Any other non-whitespace ASCII Character instead of
k
can be chosen - Your program must support the following operations:
- addition (
+
,plus()
,add()
,sum()
) - subtraction (
-
,minus()
,subtract()
) - exponentiation (
**
,^
,pow()
or others, should be specified), with support to negative bases and exponents - square root in the form of
sqrt(k)
,k^0.5
,k**0.5
, or however else you wish - multiplication and division
- addition (
- The submission can either be a full program or a function, while mentioning its usage
- Any trailing / leading whitespace is allowed when outputting
- Minimum precision: 2 decimal places
Test Cases (with k
)
+---------------+--------------+
| Input = E(k) | Output |
|---------------+--------------|
|2*k | 30 |
|---------------+--------------|
|sqrt(k) | 8.38 | (* with minimum decimal precision)
|---------------+--------------|
|k+k/2+k**2 | 77.5 |
|---------------+--------------|
|k**2 | 55 |
+---------------+--------------+
The score will be the number of bytes (of the source + compiler flags). The lowest scoring valid submission wins, while taking note that these loopholes are strictly forbidden. Here is a Python pseudo-code, to make things clearer.
plus()
instead of+
? (Same questions for all other operators too) \$\endgroup\$plus()
,add()
,sum()
and equivalents are allowed. See the edit. \$\endgroup\$N N2/+N2**+
. \$\endgroup\$E(x)
@ComradeSparklePony \$\endgroup\$