## Hackerrank – Problem Statement

A description of the problem can be found on Hackerrank.

## Solution

- function
`f`

is an applied*algebraic expression*to`x`

as in problem description - function
`area`

is area of the cycle ($$\Pi r^2$$) with center`0`

and radius value of`function(x)`

- function
`summation`

is applied once for function`f`

and one for function`area`

I created solution in:

All solutions are also available on my GitHub.

## Scala

1 2 3 4 5 6 7 8 9 10 11 12 13 |
def f(coefficients: List[Int], powers:List[Int], x: Double): Double = { coefficients.indices.map(i => coefficients(i) * Math.pow(x, powers(i))).sum } def area(coefficients: List[Int], powers: List[Int], x: Double): Double = { scala.math.Pi * scala.math.pow(f(coefficients, powers, x), 2) } def summation(func: (List[Int], List[Int], Double) => Double, upperLimit: Int, lowerLimit: Int, coefficients: List[Int], powers: List[Int]): Double = { val range = lowerLimit.toDouble to upperLimit.toDouble by 0.001 range.map(func(coefficients, powers, _)).sum * 0.001 } |