Mian-Chowla sequence: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
m (→{{header|Wren}}: Changed to Wren S/H) |
|||
(3 intermediate revisions by 2 users not shown) | |||
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()
}
Line 1,952 ⟶ 1,949:
=={{header|Sidef}}==
{{trans|Go}}
<syntaxhighlight lang="ruby">var (n, sums, ts, mc) = (100, Set(
var st = Time.
for i in (1 ..^ n) {
for j in (mc[i-1]+1 .. Inf) {
Line 1,959 ⟶ 1,956:
for k in (0 .. i) {
var sum = mc[k]+j
if (sums.
ts.clear
break
Line 1,966 ⟶ 1,963:
}
if (ts.len > 0) {
sums |=
break
}
}
}
var et = (Time.
var s = " of the Mian-Chowla sequence are:\n"
say "The first 30 terms#{s}#{mc.
say "Terms 91 to 100#{s}#{mc.
say "Computation time was #{et} seconds."</syntaxhighlight>
{{out}}
Line 1,983 ⟶ 1,980:
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219
Computation time was
=={{header|Swift}}==
Line 2,185 ⟶ 2,182:
=={{header|Wren}}==
{{trans|C#}}
<syntaxhighlight lang="
var mc = List.filled(n, 0)
var sums = {}
|