From ae3bba1423d568fa73b5e51810575fb23a7859d7 Mon Sep 17 00:00:00 2001 From: UPENDRA FALAK <92383431+Upendrafalak@users.noreply.github.com> Date: Wed, 27 Sep 2023 15:32:27 +0530 Subject: [PATCH 1/4] translated ExponenciacaoRecursiva.kt to English --- src/kotlin/ExponenciacaoRecursiva.kt | 26 -------------------------- src/kotlin/RecursiveExponentiation.kt | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 26 deletions(-) delete mode 100644 src/kotlin/ExponenciacaoRecursiva.kt create mode 100644 src/kotlin/RecursiveExponentiation.kt diff --git a/src/kotlin/ExponenciacaoRecursiva.kt b/src/kotlin/ExponenciacaoRecursiva.kt deleted file mode 100644 index c444ea26..00000000 --- a/src/kotlin/ExponenciacaoRecursiva.kt +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Função "exponenciacaoRecursiva" - * - * 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. - * - * @author Versão do algoritmo para Kotlin: Alfredo Paes - * @see https://github.com/Alfredo-Paes - * - * @param base é do tipo inteiro(Int) - * @param expoente é do tipo inteiro(Int) - * - * @return retornará o número *base* elevado pelo *expoente*. A função retorna um valor do tipo *Long*. - */ -fun exponenciacaoRecursiva(base: Int, expoente: Int): Long { - return if (expoente === 0) { - 1 - }; else { - base * exponenciacaoRecursiva(base, expoente - 1) - } -} - -fun main() { - println(exponenciacaoRecursiva(2, 3)) -} diff --git a/src/kotlin/RecursiveExponentiation.kt b/src/kotlin/RecursiveExponentiation.kt new file mode 100644 index 00000000..788e19fc --- /dev/null +++ b/src/kotlin/RecursiveExponentiation.kt @@ -0,0 +1,25 @@ +/** + * "exponentiationRecursive" function + * + * 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 Algorithm version for Kotlin: Alfredo Paes + * @see https://github.com/Alfredo-Paes + * + * @param base is of type integer (Int) + * @param exponent is of type integer (Int) + * + * @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) { + 1 + }; else { + base * exponentiationRecursive(base, exponent - 1) + } +} + +fun main() { + println(exponentiationRecursive(2, 3)) +} \ No newline at end of file From a1e1e71a2f34819596faf5fb3ff59b1e1dff63fb Mon Sep 17 00:00:00 2001 From: UPENDRA FALAK <92383431+Upendrafalak@users.noreply.github.com> Date: Wed, 27 Sep 2023 15:51:02 +0530 Subject: [PATCH 2/4] translated Fibonacci.kt and Factorial.kt to English --- src/kotlin/Factorial.kt | 27 +++++++++++++++++++++++++++ src/kotlin/Fatorial.kt | 27 --------------------------- src/kotlin/Fibonacci.kt | 24 ++++++++++-------------- 3 files changed, 37 insertions(+), 41 deletions(-) create mode 100644 src/kotlin/Factorial.kt delete mode 100644 src/kotlin/Fatorial.kt diff --git a/src/kotlin/Factorial.kt b/src/kotlin/Factorial.kt new file mode 100644 index 00000000..535e196e --- /dev/null +++ b/src/kotlin/Factorial.kt @@ -0,0 +1,27 @@ +/** + * "factorial" function + * + * The *factorial* function presents the values of multiplying *n numbers* by their predecessors greater than or equal to 1. + * + * @author Algorithm version for Kotlin: Alfredo Paes + * @see https://github.com/Alfredo-Paes + * + * @param number is of type integer (Int) + * + * @return will return a number of type *Long* in which the type is assigned to the *factorial* variable. + */ + +fun factorial(number: Int) { + val initialNumber: Int = number + var factorial: Long = 1 + + for (i in 1..initialNumber) { + factorial *= i.toLong() + } + + println("Factorial of $number! is $factorial") +} + +fun main() { + factorial(7) +} \ No newline at end of file diff --git a/src/kotlin/Fatorial.kt b/src/kotlin/Fatorial.kt deleted file mode 100644 index 16adfb03..00000000 --- a/src/kotlin/Fatorial.kt +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Função "fatorial" - * - * A função *Fatorial* apresenta os valores da multiplicação *n números* por seus antecessores maiores ou iguais a 1. - * - * @author Versão do algoritmo para Kotlin: Alfredo Paes - * @see https://github.com/Alfredo-Paes - * - * @param numero é do tipo inteiro(Int) - * - * @return retornará um número do tipo *Long* no qual o tipo está atribuido para a variável *fatorial*. - */ - -fun fatorial(numero: Int) { - val numeroInicial: Int = numero - var fatorial: Long = 1 - - for (i in 1..numeroInicial) { - fatorial *= i.toLong() - } - - println("Fatorial de $numero! é $fatorial") -} - -fun main() { - fatorial(7) -} diff --git a/src/kotlin/Fibonacci.kt b/src/kotlin/Fibonacci.kt index 73590167..dcf48c95 100644 --- a/src/kotlin/Fibonacci.kt +++ b/src/kotlin/Fibonacci.kt @@ -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 + * @author Algorithm version for Kotlin: Alfredo Paes * @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)) +} \ No newline at end of file From b2bc81a9dccdceaec49f6c1c7c8d697013ea5568 Mon Sep 17 00:00:00 2001 From: UPENDRA FALAK <92383431+Upendrafalak@users.noreply.github.com> Date: Wed, 27 Sep 2023 22:31:40 +0530 Subject: [PATCH 3/4] Updated the koitlin file names --- .../{RecursiveExponentiation.kt => ExponenciacaoRecursiva.kt} | 0 src/kotlin/{Factorial.kt => Fatorial.kt} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/kotlin/{RecursiveExponentiation.kt => ExponenciacaoRecursiva.kt} (100%) rename src/kotlin/{Factorial.kt => Fatorial.kt} (100%) diff --git a/src/kotlin/RecursiveExponentiation.kt b/src/kotlin/ExponenciacaoRecursiva.kt similarity index 100% rename from src/kotlin/RecursiveExponentiation.kt rename to src/kotlin/ExponenciacaoRecursiva.kt diff --git a/src/kotlin/Factorial.kt b/src/kotlin/Fatorial.kt similarity index 100% rename from src/kotlin/Factorial.kt rename to src/kotlin/Fatorial.kt From dde78ecf8cd0ab9a129186337cb4faa932501a51 Mon Sep 17 00:00:00 2001 From: UPENDRA FALAK <2020.upendra.falak@ves.ac.in> Date: Fri, 29 Sep 2023 11:09:01 +0530 Subject: [PATCH 4/4] Formated the code --- src/kotlin/ExponenciacaoRecursiva.kt | 2 +- src/kotlin/Fatorial.kt | 4 ++-- src/kotlin/Fibonacci.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kotlin/ExponenciacaoRecursiva.kt b/src/kotlin/ExponenciacaoRecursiva.kt index 788e19fc..4e96bf1c 100644 --- a/src/kotlin/ExponenciacaoRecursiva.kt +++ b/src/kotlin/ExponenciacaoRecursiva.kt @@ -22,4 +22,4 @@ fun exponentiationRecursive(base: Int, exponent: Int): Long { fun main() { println(exponentiationRecursive(2, 3)) -} \ No newline at end of file +} diff --git a/src/kotlin/Fatorial.kt b/src/kotlin/Fatorial.kt index 535e196e..faf6756a 100644 --- a/src/kotlin/Fatorial.kt +++ b/src/kotlin/Fatorial.kt @@ -13,7 +13,7 @@ fun factorial(number: Int) { val initialNumber: Int = number - var factorial: Long = 1 + var factorial: Long = 1 for (i in 1..initialNumber) { factorial *= i.toLong() @@ -24,4 +24,4 @@ fun factorial(number: Int) { fun main() { factorial(7) -} \ No newline at end of file +} diff --git a/src/kotlin/Fibonacci.kt b/src/kotlin/Fibonacci.kt index dcf48c95..440f2d61 100644 --- a/src/kotlin/Fibonacci.kt +++ b/src/kotlin/Fibonacci.kt @@ -21,4 +21,4 @@ fun fibonacciRecursive(number: Int): Int { fun main() { println(fibonacciRecursive(5)) -} \ No newline at end of file +}