Skip to content

Commit 627890b

Browse files
ctruchiCLOVIS-AI
authored andcommitted
tp2 step 3 solution
1 parent a9d26ac commit 627890b

File tree

1 file changed

+17
-5
lines changed
  • tp2/src/main/kotlin/fmt/kotlin/fundamentals

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package fmt.kotlin.fundamentals
22

33
fun main() {
4-
println(getFirstPrimeNumbers())
4+
println(getFirstPrimeNumbers(1, 2, 3))
55
}
66

77
private const val MIN = 0
@@ -13,10 +13,22 @@ private const val prefix = "["
1313
private const val separator = ", "
1414
private const val suffix = "]"
1515

16-
fun getFirstPrimeNumbers(nbToFind: Int = 10): String = when {
17-
nbToFind <= MIN -> ERROR_MIN
18-
nbToFind > MAX -> ERROR_MAX
19-
else -> computeFirstPrimeNumbers(nbToFind)
16+
17+
fun getFirstPrimeNumbers(vararg nbToFindBatches: Int): String {
18+
var firstLine = true
19+
var result = ""
20+
for (nbToFind in nbToFindBatches) {
21+
if (!firstLine) {
22+
result += "\n"
23+
}
24+
result += when {
25+
nbToFind <= MIN -> ERROR_MIN
26+
nbToFind > MAX -> ERROR_MAX
27+
else -> computeFirstPrimeNumbers(nbToFind)
28+
}
29+
firstLine = false
30+
}
31+
return result
2032
}
2133

2234
private fun computeFirstPrimeNumbers(nbToFind: Int = 10): String {

0 commit comments

Comments
 (0)