val power Int Int Int case if case if power n-1 case power power

1
2
3
4
5
6
val power: Int => (Int => Int) =
n => {
case x if (n == 0) => 1
case x if (n%2 == 1) => power(n-1)(x) * x
case x => power(n/2)(x) * power(n/2)(x)
}