Mian-Chowla sequence: Difference between revisions

Content added Content deleted
Line 1,949: Line 1,949:
=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Go}}
{{trans|Go}}
<syntaxhighlight lang="ruby">var (n, sums, ts, mc) = (100, Set([2]), [], [1])
<syntaxhighlight lang="ruby">var (n, sums, ts, mc) = (100, Set(2), [], [1])
var st = Time.micro_sec
var st = Time.micro
for i in (1 ..^ n) {
for i in (1 ..^ n) {
for j in (mc[i-1]+1 .. Inf) {
for j in (mc[i-1]+1 .. Inf) {
Line 1,956: Line 1,956:
for k in (0 .. i) {
for k in (0 .. i) {
var sum = mc[k]+j
var sum = mc[k]+j
if (sums.exists(sum)) {
if (sums.has(sum)) {
ts.clear
ts.clear
break
break
Line 1,963: Line 1,963:
}
}
if (ts.len > 0) {
if (ts.len > 0) {
sums = (sums|Set(ts...))
sums |= Set(ts...)
break
break
}
}
}
}
}
}
var et = (Time.micro_sec - st)
var et = (Time.micro - st)
var s = " of the Mian-Chowla sequence are:\n"
var s = " of the Mian-Chowla sequence are:\n"
say "The first 30 terms#{s}#{mc.ft(0, 29).join(' ')}\n"
say "The first 30 terms#{s}#{mc.first(30).join(' ')}\n"
say "Terms 91 to 100#{s}#{mc.ft(90, 99).join(' ')}\n"
say "Terms 91 to 100#{s}#{mc.slice(90).first(10).join(' ')}\n"
say "Computation time was #{et} seconds."</syntaxhighlight>
say "Computation time was #{et} seconds."</syntaxhighlight>
{{out}}
{{out}}
Line 1,980: Line 1,980:
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219


Computation time was 3.9831 seconds.</pre>
Computation time was 2.6288 seconds.</pre>


=={{header|Swift}}==
=={{header|Swift}}==