OFFSET
0,3
LINKS
Wikipedia, Permutation
MAPLE
g:= proc(n) g(n):= (t-> issqr(t+4) or issqr(t-4))(5*n^2) 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_] := With[{t = 5 n^2}, IntegerQ@Sqrt[t + 4] || IntegerQ@Sqrt[t - 4]];
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