The Mian–Chowla sequence is an integer sequence defined recursively.



Mian–Chowla is an infinite instance of a Sidon sequence, and belongs to the class known as B₂ sequences.



The sequence starts with:

a1 = 1
then for n > 1, an is the smallest positive integer such that every pairwise sum

ai + aj 
is distinct, for all i and j less than or equal to n.

The Task

 Find and display, here, on this page the first 30 terms of the Mian–Chowla sequence.
 Find and display, here, on this page the 91st through 100th terms of the Mian–Chowla sequence.


Demonstrating working through the first few terms longhand:

a1 = 1
1 + 1 = 2
Speculatively try a2 = 2

1 + 1 = 2
1 + 2 = 3
2 + 2 = 4
There are no repeated sums so 2 is the next number in the sequence.

Speculatively try a3 = 3

1 + 1 = 2
1 + 2 = 3 
1 + 3 = 4
2 + 2 = 4
2 + 3 = 5
3 + 3 = 6
Sum of 4 is repeated so 3 is rejected.

Speculatively try a3 = 4

1 + 1 = 2
1 + 2 = 3
1 + 4 = 5
2 + 2 = 4
2 + 4 = 6
4 + 4 = 8
There are no repeated sums so 4 is the next number in the sequence.

And so on...

See also

 OEIS:A005282 Mian-Chowla sequence
function mian_chowla(integer n)
sequence mc = {1},
         is = {false,true}
    integer len_is = 2, s
    for i=2 to n do
        sequence isx = {}
        integer j = mc[i-1]+1
        mc = append(mc,j)
        while true do
            for k=1 to length(mc) do
                s = mc[k] + j
                if s<=len_is and is[s] then
                    isx = {}
                    exit
                end if
                isx = append(isx,s)
            end for
            if length(isx) then
                s = isx[$]
                if s>len_is then
                    is &= repeat(false,s-len_is)
                    len_is = length(is)
                end if
                for k=1 to length(isx) do
                    is[isx[k]] = true
                end for
                exit
            end if
            j += 1
            mc[i] = j
        end while
    end for
    return mc
end function
 
atom t0 = time()
sequence mc = mian_chowla(100)
printf(1,"The first 30 terms of the Mian-Chowla sequence are:\n %V\n",{mc[1..30]})
printf(1,"Terms 91 to 100 of the Mian-Chowla sequence are:\n %V\n",{mc[91..100]})
printf(1,"completed in %s\n",{elapsed(time()-t0)})
