login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Number of cyclic arrangements of S={1,2,...,n} such that the difference between any two neighbors is at most 4.
16

%I #25 Oct 25 2018 17:25:36

%S 1,1,1,3,12,36,90,214,521,1335,3473,9016,23220,59428,152052,389636,

%T 999776,2566517,6586825,16899574,43352560,111213798,285319258,

%U 732016006,1878072638,4818362046,12361809384,31714901077,81366445061,208750870961

%N Number of cyclic arrangements of S={1,2,...,n} such that the difference between any two neighbors is at most 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 Andrew Howroyd, <a href="/A242526/b242526.txt">Table of n, a(n) for n = 1..100</a>

%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.

%F From _Andrew Howroyd_, Apr 08 2016: (Start)

%F Empirical: a(n) = 2*a(n-1) + a(n-2) - a(n-4) + 9*a(n-5) + 5*a(n-6) - a(n-7) - 7*a(n-8) - 10*a(n-9) + 2*a(n-10) + 2*a(n-11) + 2*a(n-12) + 4*a(n-13) - 2*a(n-17) - a(n-18) for n>20.

%F Empirical g.f.: x + (3 - 6*x - 2*x^2 - x^3 + 3*x^4 - 22*x^5 - 5*x^6 + x^7 + 8*x^8 + 14*x^9 - 6*x^10 + 2*x^11 - 6*x^12 - 6*x^13 - 3*x^15 + x^16 + 3*x^17) / (1 - 2*x - x^2 + x^4 - 9*x^5 - 5*x^6 + x^7 + 7*x^8 + 10*x^9 - 2*x^10 - 2*x^11 - 2*x^12 - 4*x^13 + 2*x^17 + x^18). (End)

%e The 3 cycles of length n=4 are: {1,2,3,4},{1,2,4,3},{1,3,2,4}.

%e The first and the last of the 1335 such cycles of length n=10 are:

%e C_1={1,2,3,4,6,7,8,10,9,5}, C_1335={1,4,8,10,9,7,6,3,2,5}.

%t A242526[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 Join[{1, 1}, Table[A242526[n], {n, 3, 10}]]

%t (* OR, a less simple, but more efficient implementation. *)

%t A242526[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 A242526[n, Join[perm, {new}],

%t Complement[Range[2, n], perm, {new}]];

%t ];

%t Return[ct];

%t ];

%t ];

%t Join[{1, 1}, Table[ct = 0; A242526[n, {1}, Range[2, n]]/2, {n, 3, 12}] ](* _Robert Price_, Oct 25 2018 *)

%o (C++) See the link.

%Y Cf. A242519, A242520, A242521, A242522, A242523, A242524, A242525, A242527, A242528, A242529, A242530, A242531, A242532, A242533, A242534.

%K nonn

%O 1,4

%A _Stanislav Sykora_, May 27 2014

%E a(22)-a(30) from _Andrew Howroyd_, Apr 08 2016