Skip to content

Commit 4aa86cd

Browse files
committed
tp8 solution
1 parent 3e9fe00 commit 4aa86cd

File tree

1 file changed

+8
-1
lines changed
  • tp8/src/main/kotlin/fmt/kotlin/fundamentals

1 file changed

+8
-1
lines changed

tp8/src/main/kotlin/fmt/kotlin/fundamentals/Tp8.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@ package fmt.kotlin.fundamentals
22

33
class Tp8 {
44

5-
fun getFirstPrimeNumbers(nbToFind: Int) = emptyList()
5+
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 }
613
}

0 commit comments

Comments
 (0)