Skip to content

Commit

Permalink
tp8 step 1 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ctruchi committed Feb 14, 2025
1 parent 89da25b commit 1a790c2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tp8/src/main/kotlin/fmt/kotlin/fundamentals/Tp8.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@ package fmt.kotlin.fundamentals

class Tp8 {

fun getFirstPrimeNumbers(nbToFind: Int) = emptyList()
fun getFirstPrimeNumbers(nbToFind: Int) = generateSequence(2) { it + 1 }
.filter { it.isPrime() }
.take(nbToFind)
.toList()

private fun Int.isPrime() = generateSequence(2) { it + 1 }
.takeWhile { it < this }
.none() { this % it == 0 }
}

0 comments on commit 1a790c2

Please sign in to comment.