[go: up one dir, main page]

login
A256210
Lexicographically earliest permutation of positive integers starting with 2 such that a(a(n)+a(n+1)) is odd for all n.
5
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, 31, 24, 26, 28, 33, 30, 35, 32, 37, 34, 39, 36, 41, 38, 40, 43, 45, 47, 42, 44, 49, 46, 48, 51, 50, 53, 52, 55, 57, 59, 54, 56, 58, 61, 63, 60, 65, 62, 67, 64, 69
OFFSET
1,1
COMMENTS
This is the sequence U defined in the comments on A255003.
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
Cf. A255003.
Cf. A256371 (inverse), A256372 (fixed points).
Sequence in context: A258654 A171085 A288538 * A256371 A064429 A234751
KEYWORD
nonn
AUTHOR
N. J. A. Sloane, Mar 26 2015
STATUS
approved