%I #21 Aug 04 2018 10:47:12
%S 2,1,3,5,4,6,7,9,11,13,8,10,15,12,14,17,16,19,18,21,23,20,22,25,27,29,
%T 31,24,26,28,33,30,35,32,37,34,39,36,41,38,40,43,45,47,42,44,49,46,48,
%U 51,50,53,52,55,57,59,54,56,58,61,63,60,65,62,67,64,69
%N Lexicographically earliest permutation of positive integers starting with 2 such that a(a(n)+a(n+1)) is odd for all n.
%C This is the sequence U defined in the comments on A255003.
%H Alois P. Heinz, <a href="/A256210/b256210.txt">Table of n, a(n) for n = 1..20000</a>
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%p N:= 100: # to get a(n) for n <= N
%p maxodd:= -1:
%p maxeven:= 2:
%p a[1]:= 2:
%p needodd:= {}:
%p for n from 2 to N do
%p if member(n,needodd) or maxodd < maxeven then
%p a[n]:= maxodd + 2;
%p maxodd:= a[n];
%p else
%p a[n]:= maxeven + 2;
%p maxeven:= a[n];
%p fi;
%p needodd:= needodd union {a[n-1]+a[n]};
%p od:
%p seq(a[n],n=1..N); # _Robert Israel_, Mar 26 2015
%t nn = 100;
%t maxodd = -1;
%t maxeven = 2;
%t a[1] = 2;
%t needodd = {};
%t For[n = 2, n <= nn, n++,
%t If[MemberQ[needodd, n] || maxodd < maxeven,
%t a[n] = maxodd + 2;
%t maxodd = a[n]
%t ,
%t a[n] = maxeven + 2;
%t maxeven = a[n]
%t ];
%t needodd = needodd ~Union~ {a[n-1]+a[n]};
%t ];
%t Array[a, nn] (* _Jean-François Alcover_, Aug 04 2018, after _Robert Israel_ *)
%o (Haskell) after Robert Israel's Maple program
%o import Data.IntSet (empty, member, insert)
%o a256210 n = a256210_list !! (n-1)
%o a256210_list = 2 : f [2 ..] 2 [1, 3 ..] [4, 6 ..] empty where
%o f (x:xs) y us'@(u:us) vs'@(v:vs) s
%o | member x s || u < v = u : f xs u us vs' (insert (y + u) s)
%o | otherwise = v : f xs v us' vs (insert (y + v) s)
%o -- _Reinhard Zumkeller_, Mar 26 2015
%Y Cf. A255003.
%Y Cf. A256371 (inverse), A256372 (fixed points).
%K nonn
%O 1,1
%A _N. J. A. Sloane_, Mar 26 2015