Skip to content

Commit 6bff429

Browse files
ctruchiCLOVIS-AI
authored andcommitted
tp2 step 2 solution
1 parent fccf6fb commit 6bff429

File tree

1 file changed

+12
-1
lines changed
  • tp2/src/main/kotlin/fmt/kotlin/fundamentals

1 file changed

+12
-1
lines changed

tp2/src/main/kotlin/fmt/kotlin/fundamentals/Tp2.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ fun main() {
44
println(getFirstPrimeNumbers())
55
}
66

7+
private const val MIN = 0
8+
private const val MAX = 10000
9+
private const val ERROR_MIN = "nbToFind must be > 0"
10+
private const val ERROR_MAX = "nbToFind must be < 10000"
11+
712
private const val prefix = "["
813
private const val separator = ", "
914
private const val suffix = "]"
1015

11-
fun getFirstPrimeNumbers(nbToFind: Int = 10): String {
16+
fun getFirstPrimeNumbers(nbToFind: Int = 10): String = when {
17+
nbToFind <= MIN -> ERROR_MIN
18+
nbToFind > MAX -> ERROR_MAX
19+
else -> computeFirstPrimeNumbers(nbToFind)
20+
}
21+
22+
private fun computeFirstPrimeNumbers(nbToFind: Int = 10): String {
1223
var current = 2
1324
var found = ""
1425
var nbFound = 0

0 commit comments

Comments
 (0)