OFFSET
0,4
LINKS
Wikipedia, Permutation
EXAMPLE
a(2) = 1: 21.
a(3) = 2: 231, 312.
a(4) = 4: 2143, 2413, 3142, 3412.
a(5) = 6: 21453, 21534, 23154, 24153, 31254, 31524.
a(6) = 13: 214365, 214635, 215364, 215634, 231564, 231645, 241365, 241635, 312564, 312645, 314265, 315264, 341265.
MAPLE
g:= proc(n) local i; 1; for i from 2 do
if n=% then true; break elif n<% then false; break fi;
%*i od; g(n):=%
end:
b:= proc(s) option remember; (n-> `if`(n=0, 1, add(`if`(
g(abs(n-j)), b(s minus {j}), 0), j=s)))(nops(s))
end:
a:= n-> b({$1..n}):
seq(a(n), n=0..20);
MATHEMATICA
factorialQ[n_] := factorialQ[n] = Module[{i, k = 1}, For[i = 2, True, i++, If[n == k, Return[True]]; If[n < k, Return[False]]; k = k*i]];
b[s_] := b[s] = With[{n = Length[s]}, If[n == 0, 1, Sum[If[factorialQ[Abs[n - j]], b[s ~Complement~ {j}], 0], {j, s}]]];
a[n_] := b[Range[n]];
a /@ Range[0, 20] (* Jean-François Alcover, Mar 25 2021, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Feb 25 2019
STATUS
approved