Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Exponentitaion (recursive): Scala implementation
  • Loading branch information
Paul Sasieta Arana committed Oct 29, 2024
commit 1518fcf3d13206d95b6e7c8144d833600dd476df
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ In order to achieve greater coverage and encourage more people to contribute to
</a>
</td>
<td> <!-- Scala -->
<a href="./CONTRIBUTING.md">
<img align="center" height="25" src="./logos/github.svg" />
<a href="./src/scala/ExponentiationRecursive.md">
<img align="center" height="25" src="./logos/scala.svg" />
</a>
</td>
<td> <!-- Kotlin -->
Expand Down
11 changes: 11 additions & 0 deletions src/scala/ExponentiationRecursive.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scala.annotation.tailrec

@tailrec
def exponentiationRecursive(base: Int, exponent: Int, accumulator: Int = 1): Int = exponent match {
case 0 => accumulator
case _ => exponentiationRecursive(base, exponent - 1, accumulator * base)
}

object Main extends App {
println("5 ^ 3 = " + exponentiationRecursive(5, 3))
}
Loading