OFFSET
1,3
COMMENTS
Consider pairs of sequences A = a_1 a_2 a_3 a_4 ... and B = b_1 b_2 b_3 ... such that
1: All the terms are nonnegative integers
2: The terms of A are strictly increasing
3: The terms of B are strictly increasing
4: All the numbers |a_i - b_j| are distinct
5: The terms are computed in the following order: a(1), b(1), a(2), b(2), ..., b(n-1), a(n), b(n), a(n+1), ... and always the smallest value is chosen that satisfies constraints 1-4.
Computed by Alois P. Heinz and Wouter Meeussen, Mar 27 2010
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..200
MAPLE
# Maple program from Alois P. Heinz:
ab:=proc() false end: ab(0):=true:
a:= proc(n) option remember;
local ok, i, k, s;
if n=1 then 0
else b(n-1);
for k from a(n-1)+1 do
ok:=true;
for i from 1 to n-1 do
if ab(abs(k-b(i))) then ok:= false; break fi
od;
if ok then s:={};
for i from 1 to n-1 do
s:= s union {abs(k-b(i))};
od
fi;
if ok and nops(s)=n-1 then break fi
od;
for i from 1 to n-1 do
ab(abs(k-b(i))):=true
od;
k
fi
end;
b:= proc(n) option remember;
local ok, i, k, s;
if n=1 then 0
else a(n);
for k from b(n-1)+1 do
ok:=true;
for i from 1 to n do
if ab(abs(k-a(i))) then ok:= false; break fi
od;
if ok then s:={};
for i from 1 to n do
s:= s union {abs(k-a(i))};
od
fi;
if ok and nops(s)=n then break fi
od;
for i from 1 to n do
ab(abs(k-a(i))):=true
od;
k
fi
end;
seq(a(n), n=1..80);
seq(b(n), n=1..80);
MATHEMATICA
ClearAll[ab, a, b]; ab[_] = False; ab[0] = True; a[n_] := a[n] = Module[{ ok, i, k, s}, If[ n == 1 , 0, b[n-1]; For[ k = a[n-1] + 1 , True, k++, ok = True; For[ i = 1 , i <= n-1, i++, If[ ab[Abs[k - b[i]]] , ok = False; Break[] ]]; If[ ok , s = {}; For[ i=1 , i <= n-1 , i++, s = s ~Union~ {Abs[k - b[i]]}; ]]; If[ ok && (Length[s] == n-1) , Break[] ]]; For[ i=1 , i <= n-1 , i++, ab[Abs[k - b[i]]] = True]; k]]; b[n_] := b[n] = Module[{ ok, i, k, s}, If[ n == 1 , 0, a[n]; For[ k = b[n-1] + 1 , True, k++, ok = True; For[ i=1 , i <= n, i++, If[ ab[Abs[k - a[i]]] , ok = False; Break[] ]]; If[ ok , s = {}; For[ i=1 , i <= n , i++, s = s ~Union~ {Abs[k - a[i]]}; ]]; If[ ok && Length[s] == n , Break[] ]]; For[ i=1 , i <= n, i++, ab[Abs[k - a[i]]] := True]; k]]; Table[a[n], {n, 1, 45}] (* Jean-François Alcover, Aug 13 2012, translated from Alois P. Heinz's Maple program *)
CROSSREFS
KEYWORD
nonn,nice
AUTHOR
R. K. Guy and N. J. A. Sloane, Mar 27 2010
EXTENSIONS
Comments clarified by Zak Seidov and Alois P. Heinz, Apr 13 2010.
STATUS
approved