Mian-Chowla sequence: Difference between revisions

Added 11l
(add freebasic)
(Added 11l)
Line 63:
 
:* [[oeis:A005282|OEIS:A005282 Mian-Chowla sequence]]
 
=={{header|11l}}==
{{trans|C++}}
 
<lang 11l>F contains(sums, s, ss)
L(i) 0 .< ss
I sums[i] == s
R 1B
R 0B
 
F mian_chowla()
V n = 100
V mc = [0] * n
mc[0] = 1
V sums = [0] * ((n * (n + 1)) >> 1)
sums[0] = 2
V ss = 1
L(i) 1 .< n
V le = ss
V j = mc[i - 1] + 1
L
mc[i] = j
V nxtJ = 0B
L(k) 0 .. i
V sum = mc[k] + j
I contains(sums, sum, ss)
ss = le
nxtJ = 1B
L.break
sums[ss] = sum
ss++
I !nxtJ
L.break
j++
R mc
 
print(‘The first 30 terms of the Mian-Chowla sequence are:’)
V mc = mian_chowla()
print_elements(mc[0.<30])
print()
print(‘Terms 91 to 100 of the Mian-Chowla sequence are:’)
print_elements(mc[90..])</lang>
 
{{out}}
<pre>
The first 30 terms of the Mian-Chowla sequence are:
1 2 4 8 13 21 31 45 66 81 97 123 148 182 204 252 290 361 401 475 565 593 662 775 822 916 970 1016 1159 1312
 
Terms 91 to 100 of the Mian-Chowla sequence are:
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219
</pre>
 
=={{header|Ada}}==
1,480

edits