**Warning**: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in

**/nfsmnt/hosting2_2/a/b/abebc507-bf25-4cf8-8cfa-a3d31b5acb3d/pidanic.com/web/wp-content/plugins/latex/latex.php**on line

**47**

**Warning**: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in

**/nfsmnt/hosting2_2/a/b/abebc507-bf25-4cf8-8cfa-a3d31b5acb3d/pidanic.com/web/wp-content/plugins/latex/latex.php**on line

**49**

## 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 () 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 } |