OFFSET
1,1
COMMENTS
This is the sequence U defined in the comments on A255003.
LINKS
MAPLE
N:= 100: # to get a(n) for n <= N
maxodd:= -1:
maxeven:= 2:
a[1]:= 2:
needodd:= {}:
for n from 2 to N do
if member(n, needodd) or maxodd < maxeven then
a[n]:= maxodd + 2;
maxodd:= a[n];
else
a[n]:= maxeven + 2;
maxeven:= a[n];
fi;
needodd:= needodd union {a[n-1]+a[n]};
od:
seq(a[n], n=1..N); # Robert Israel, Mar 26 2015
MATHEMATICA
nn = 100;
maxodd = -1;
maxeven = 2;
a[1] = 2;
needodd = {};
For[n = 2, n <= nn, n++,
If[MemberQ[needodd, n] || maxodd < maxeven,
a[n] = maxodd + 2;
maxodd = a[n]
,
a[n] = maxeven + 2;
maxeven = a[n]
];
needodd = needodd ~Union~ {a[n-1]+a[n]};
];
Array[a, nn] (* Jean-François Alcover, Aug 04 2018, after Robert Israel *)
PROG
(Haskell) after Robert Israel's Maple program
import Data.IntSet (empty, member, insert)
a256210 n = a256210_list !! (n-1)
a256210_list = 2 : f [2 ..] 2 [1, 3 ..] [4, 6 ..] empty where
f (x:xs) y us'@(u:us) vs'@(v:vs) s
| member x s || u < v = u : f xs u us vs' (insert (y + u) s)
| otherwise = v : f xs v us' vs (insert (y + v) s)
-- Reinhard Zumkeller, Mar 26 2015
CROSSREFS
KEYWORD
nonn
AUTHOR
N. J. A. Sloane, Mar 26 2015
STATUS
approved