-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6706 from iRetr0o/main
Reto #4 - Kotlin
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/kotlin/iRetr0o.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |