From a1a9f2ad1a92c22134a5b8e7471c145f173b9df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Guti=C3=A9rrez?= <98203302+iRetr0o@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:44:29 -0600 Subject: [PATCH] feat: Reto #4 - Kotlin --- .../kotlin/iRetr0o.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/kotlin/iRetr0o.kt diff --git a/Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/kotlin/iRetr0o.kt b/Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/kotlin/iRetr0o.kt new file mode 100644 index 0000000000..47c0489548 --- /dev/null +++ b/Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/kotlin/iRetr0o.kt @@ -0,0 +1,34 @@ +fun main() { + checkNumber(3) + checkNumber(7) +} + +fun isPrime(n: Int): Boolean { + if (n < 2) return false + for (i in 2 ..< n) { + if (n % i == 0) return false + } + return true +} + +fun isFibonacci(n: Int): Boolean { + var a = 0 + var b = 1 + while (a < n) { + val temp = a + a = b + b += temp + } + return a == n +} + +fun isEven(n: Int): Boolean { + return n % 2 == 0 +} + +fun checkNumber(n: Int) { + val prime = if (isPrime(n)) "primo" else "no es primo" + val fibonacci = if (isFibonacci(n)) "fibonacci" else "no es fibonacci" + val even = if (isEven(n)) "par" else "impar" + println("$n es $prime, $fibonacci y es $even") +} \ No newline at end of file