Skip to content

Commit 1518fcf

Browse files
author
Paul Sasieta Arana
committed
Exponentitaion (recursive): Scala implementation
1 parent 2362766 commit 1518fcf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ In order to achieve greater coverage and encourage more people to contribute to
460460
</a>
461461
</td>
462462
<td> <!-- Scala -->
463-
<a href="./CONTRIBUTING.md">
464-
<img align="center" height="25" src="./logos/github.svg" />
463+
<a href="./src/scala/ExponentiationRecursive.md">
464+
<img align="center" height="25" src="./logos/scala.svg" />
465465
</a>
466466
</td>
467467
<td> <!-- Kotlin -->
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.annotation.tailrec
2+
3+
@tailrec
4+
def exponentiationRecursive(base: Int, exponent: Int, accumulator: Int = 1): Int = exponent match {
5+
case 0 => accumulator
6+
case _ => exponentiationRecursive(base, exponent - 1, accumulator * base)
7+
}
8+
9+
object Main extends App {
10+
println("5 ^ 3 = " + exponentiationRecursive(5, 3))
11+
}

0 commit comments

Comments
 (0)