OFFSET
1,2
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..1000
Eric Angelini, Derangements on the SeqFan list, May 21 2015.
FORMULA
a(n) = 2*A081145(n)-1.
MAPLE
b:= proc() false end:
a:= proc(n) option remember; local k;
if n=1 then b(1):= true; 1
else a(n-1); for k while b(k) or
b(abs(a(n-1)-k)) by 2 do od;
b(k), b(abs(a(n-1)-k)):= true$2; k
fi
end:
seq(a(n), n=1..101);
MATHEMATICA
b[_] = False;
a[n_] := a[n] = Module[{k},
If[n == 1, b[1] = True; 1,
a[n-1]; For[k = 1, b[k] ||
b[Abs[a[n-1] - k]], k += 2];
{b[k], b[Abs[a[n-1] - k]]} = {True, True}; k]];
Table[a[n], {n, 1, 101}] (* Jean-François Alcover, Aug 01 2021, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Eric Angelini and Alois P. Heinz, May 21 2015
STATUS
approved