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

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