Mian-Chowla sequence: Difference between revisions
→Idiomatic
Line 1,236:
<syntaxhighlight lang="kotlin">
fun sumsRemainDistinct(candidate: Int,
val candidateSums = mutableListOf<Int>()
for (s in
when ((candidate + s) !in
true -> candidateSums.add(candidate + s)
false -> return false
}
}
with(
addAll(candidateSums)
add(candidate + candidate)
Line 1,253:
fun mianChowla(n: Int): List<Int> {
val
val
val sequence = generateSequence(1) { it + 1 } // [1,2,3,..]
.onEach { bufferSeq.add(it) }
▲ if (sumsRemainDistinct(candidate, mcSequence, mcSums)) {
▲ return mcSequence.toList()
}
|