We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e9fe00 commit 4aa86cdCopy full SHA for 4aa86cd
tp8/src/main/kotlin/fmt/kotlin/fundamentals/Tp8.kt
@@ -2,5 +2,12 @@ package fmt.kotlin.fundamentals
2
3
class Tp8 {
4
5
- fun getFirstPrimeNumbers(nbToFind: Int) = emptyList()
+ fun getFirstPrimeNumbers(nbToFind: Int) = generateSequence(2) { it + 1 }
6
+ .filter { it.isPrime() }
7
+ .take(nbToFind)
8
+ .toList()
9
+
10
+ private fun Int.isPrime() = generateSequence(2) { it + 1 }
11
+ .takeWhile { it < this }
12
+ .none() { this % it == 0 }
13
}
0 commit comments