OFFSET
0,3
LINKS
Wikipedia, Permutation
EXAMPLE
a(3) = 3: 123, 132, 213.
a(4) = 9: 1234, 1243, 1324, 2134, 2143, 2341, 4123, 4231, 4321.
a(5) = 19: 12345, 12354, 12435, 13245, 13254, 13452, 15234, 15342, 15432, 21345, 21354, 21435, 23415, 25314, 41235, 41352, 42315, 43215, 45312.
MAPLE
g:= proc(n) option remember; issqr(8*n+1) 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..16);
MATHEMATICA
g[n_] := g[n] = IntegerQ@Sqrt[8n+1];
b[s_] := b[s] = With[{n = Length[s]}, If[n == 0, 1, Sum[If[g[Abs[n-j]], b[s ~Complement~ {j}], 0], {j, s}]]];
a[n_] := b[Range[n]];
a /@ Range[0, 16] (* Jean-François Alcover, Mar 25 2021, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Feb 25 2019
STATUS
approved