Skip to content

Commit

Permalink
Fix Kotlin files
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvins committed Oct 25, 2024
1 parent 5ee9304 commit f61e63a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/kotlin/ExponentiationRecursive.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
*
* @return will return the *base* number raised by the *exponent*. The function returns a value of type *Long*.
*/
fun exponentiationRecursive(base: Int, exponent: Int): Long {
return if (exponent === 0) {
fun exponentiationRecursive(
base: Int,
exponent: Int,
): Long =
if (exponent === 0) {
1
}; else {
} else {
base * exponentiationRecursive(base, exponent - 1)
}
}

fun main() {
println(exponentiationRecursive(2, 3))
Expand Down
7 changes: 3 additions & 4 deletions src/kotlin/FibonacciRecursive.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
*
* @return will return a logical condition if *number* is less than or equal to 1, returns 1 otherwise, the sum of itself using the concept of *recursion* to execute this sum.
*/
fun fibonacci(number: Int): Int {
return if (number <= 1) {
fun fibonacci(number: Int): Int =
if (number <= 1) {
1
}; else {
} else {
fibonacci(number - 1) + fibonacci(number - 2)
}
}

fun main() {
println(fibonacci(5))
Expand Down
5 changes: 4 additions & 1 deletion src/kotlin/MergeSort.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ fun mergeSort(arr: IntArray): IntArray {
return merge(mergeSort(left), mergeSort(right))
}

fun merge(left: IntArray, right: IntArray): IntArray {
fun merge(
left: IntArray,
right: IntArray,
): IntArray {
var result = IntArray(left.size + right.size)
var leftIndex = 0
var rightIndex = 0
Expand Down

0 comments on commit f61e63a

Please sign in to comment.