Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/kotlin/ExponenciacaoRecursiva.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
/**
* Função "exponenciacaoRecursiva"
* "exponentiationRecursive" function
*
* A função *exponenciacaoRecursiva* apresenta os valores de um número(*base*) elevado por um *expoente*.
* Nessa função, usa -se o conceito da *recursividade*, na qual, a função criada é chamada dentro dela,
* uma ou mais vezes internamente da mesma.
* The *exponentiationRecursive* function presents the values of a number (*base*) raised by an *exponent*.
* In this function, the concept of *recursion* is used, in which the created function is called within it, one or more times internally of the same.
*
* @author Versão do algoritmo para Kotlin: Alfredo Paes <alfredo.alfpaes@gmail.com>
* @author Algorithm version for Kotlin: Alfredo Paes <alfredo.alfpaes@gmail.com>
* @see https://github.com/Alfredo-Paes
*
* @param base é do tipo inteiro(Int)
* @param expoente é do tipo inteiro(Int)
* @param base is of type integer (Int)
* @param exponent is of type integer (Int)
*
* @return retornará o número *base* elevado pelo *expoente*. A função retorna um valor do tipo *Long*.
* @return will return the *base* number raised by the *exponent*. The function returns a value of type *Long*.
*/
fun exponenciacaoRecursiva(base: Int, expoente: Int): Long {
return if (expoente === 0) {
fun exponentiationRecursive(base: Int, exponent: Int): Long {
return if (exponent === 0) {
1
}; else {
base * exponenciacaoRecursiva(base, expoente - 1)
base * exponentiationRecursive(base, exponent - 1)
}
}

fun main() {
println(exponenciacaoRecursiva(2, 3))
println(exponentiationRecursive(2, 3))
}
24 changes: 12 additions & 12 deletions src/kotlin/Fatorial.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/**
* Função "fatorial"
* "factorial" function
*
* A função *Fatorial* apresenta os valores da multiplicação *n números* por seus antecessores maiores ou iguais a 1.
* The *factorial* function presents the values of multiplying *n numbers* by their predecessors greater than or equal to 1.
*
* @author Versão do algoritmo para Kotlin: Alfredo Paes <alfredo.alfpaes@gmail.com>
* @author Algorithm version for Kotlin: Alfredo Paes <alfredo.alfpaes@gmail.com>
* @see https://github.com/Alfredo-Paes
*
* @param numero é do tipo inteiro(Int)
* @param number is of type integer (Int)
*
* @return retornará um número do tipo *Long* no qual o tipo está atribuido para a variável *fatorial*.
* @return will return a number of type *Long* in which the type is assigned to the *factorial* variable.
*/

fun fatorial(numero: Int) {
val numeroInicial: Int = numero
var fatorial: Long = 1
fun factorial(number: Int) {
val initialNumber: Int = number
var factorial: Long = 1

for (i in 1..numeroInicial) {
fatorial *= i.toLong()
for (i in 1..initialNumber) {
factorial *= i.toLong()
}

println("Fatorial de $numero! é $fatorial")
println("Factorial of $number! is $factorial")
}

fun main() {
fatorial(7)
factorial(7)
}
22 changes: 9 additions & 13 deletions src/kotlin/Fibonacci.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
/**
* Função "fibonacciRecursiva"
* "fibonacciRecursive" function
*
* A função *FibonacciRecursiva* apresenta os valores da sequência de Fibonacci em que,
* os primeiros dois termos dessa sequência são menor ou igual 1, e cada termo que vier
* a seguir será a soma dos dois números anteriores (0, 1, 1, 2, 3, 5, 8...).
* Nessa função, usa -se o conceito da *recursividade*, na qual, a função criada é chamada
* dentro dela, uma ou mais vezes internamente da mesma.
* The *fibonacciRecursive* function displays the values of the Fibonacci sequence in which, the first two terms of this sequence are less than or equal to 1, and each term that follows next will be the sum of the two previous numbers (0, 1, 1, 2, 3, 5, 8...).
* In this function, the concept of *recursion* is used, in which the created function is called within it, one or more times internally.
*
* @author Versão do algoritmo para Kotlin: Alfredo Paes <alfredo.alfpaes@gmail.com>
* @author Algorithm version for Kotlin: Alfredo Paes <alfredo.alfpaes@gmail.com>
* @see https://github.com/Alfredo-Paes
*
* @param number é do tipo inteiro(Int)
* @param number is of type integer (Int)
*
* @return retornará uma condição lógica se *number* for menor ou igual a 1, retorna 1 se não,
* o somatório dela mesma utilizando o conceito de *recursividade* para a execução deste somatório.
* @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 fibonacciRecursivo(number: Int): Int {
fun fibonacciRecursive(number: Int): Int {
return if (number <= 1) {
1
}; else {
fibonacciRecursivo(number - 1) + fibonacciRecursivo(number - 2)
fibonacciRecursive(number - 1) + fibonacciRecursive(number - 2)
}
}

fun main() {
println(fibonacciRecursivo(5))
println(fibonacciRecursive(5))
}