%I #18 Oct 24 2018 22:28:14
%S 0,0,0,0,0,0,0,0,1,24,504,8320,131384,2070087,33465414,561681192,
%T 9842378284,180447203232,3462736479324,69517900171056,
%U 1458720714556848,31955023452174314,729874911380470641,17359562438053760533,429391730229931885360
%N Number of cyclic arrangements of S={1,2,...,n} such that the difference between any two neighbors is at least 4.
%C a(n)=NPC(n;S;P) is the count of all neighbor-property cycles for a specific set S of n elements and a specific pair-property P. For more details, see the link and A242519.
%H Hiroaki Yamanouchi, <a href="/A242524/b242524.txt">Table of n, a(n) for n = 1..27</a> (terms a(1)-a(16) from _Stanislav Sykora_)
%H S. Sykora, <a href="http://dx.doi.org/10.3247/SL5Math14.002">On Neighbor-Property Cycles</a>, <a href="http://ebyte.it/library/Library.html#math">Stan's Library</a>, Volume V, 2014.
%e The shortest such cycle has length n=9: {1,5,9,4,8,3,7,2,6}.
%t A242524[n_] := Count[Map[lpf, Map[j1f, Permutations[Range[2, n]]]], 0]/2;
%t j1f[x_] := Join[{1}, x, {1}];
%t lpf[x_] := Length[Select[Abs[Differences[x]], # < 4 &]];
%t Table[A242524[n], {n, 1, 10}]
%t (* OR, a less simple, but more efficient implementation. *)
%t A242524[n_, perm_, remain_] := Module[{opt, lr, i, new},
%t If[remain == {},
%t If[Abs[First[perm] - Last[perm]] >= 4, ct++];
%t Return[ct],
%t opt = remain; lr = Length[remain];
%t For[i = 1, i <= lr, i++,
%t new = First[opt]; opt = Rest[opt];
%t If[Abs[Last[perm] - new] < 4, Continue[]];
%t A242524[n, Join[perm, {new}],
%t Complement[Range[2, n], perm, {new}]];
%t ];
%t Return[ct];
%t ];
%t ];
%t Table[ct = 0; A242524[n, {1}, Range[2, n]]/2, {n, 1, 12}] (* _Robert Price_, Oct 24 2018 *)
%o (C++) See the link.
%Y Cf. A242519, A242520, A242521, A242522, A242523, A242525, A242526, A242527, A242528, A242529, A242530, A242531, A242532, A242533, A242534.
%K nonn,hard
%O 1,10
%A _Stanislav Sykora_, May 27 2014
%E a(17)-a(25) from _Hiroaki Yamanouchi_, Aug 29 2014
|