# Greetings from The On-Line Encyclopedia of Integer Sequences! http://oeis.org/ Search: id:a174705 Showing 1-1 of 1 %I A174705 #37 Jan 02 2023 12:30:47 %S A174705 1,0,0,2,14,90,462,1668,4496,11332,31718,100258,336142,1123212, %T A174705 3614554,11128872,33226646,98298782,292626532,879380718,2654884024, %U A174705 8000680668,23965094526,71287278676,210922844362,622218231406,1833225926678,5397521667296,15876398740556,46626957024628 %N A174705 The number of permutations p of {1,...,n} such that |p(i)-p(i+1)| is in {2,3,4,5} for all i from 1 to n-1. %C A174705 For n>1, a(n)/2 is the number of Hamiltonian paths on the graph with vertex set {1,...,n} where i is adjacent to j iff |i-j| is in {2,3,4,5}. %H A174705 Andrew Howroyd, Table of n, a(n) for n = 1..100 %H A174705 W. Edwin Clark, permutations p in S_n such that m <= |p(i)-p(i+1)| <= M for i from 1 to n-1, SeqFan Discussion, Mar 2010. %p A174705 f:= proc(m, M, n) option remember; local i, l, p, cnt; l:= array([i$i=1..n]); cnt:=0; p:= proc(t) local d, j, h; if t=n then d:= `if`(t=1, m, abs(l[t]-l[t-1])); if m<=d and d<=M then cnt:= cnt+1 fi else for j from t to n do l[t],l[j]:= l[j],l[t]; d:= `if`(t=1, m, abs(l[t]-l[t-1])); if m<=d and d<=M then p(t+1) fi od; h:= l[t]; for j from t to n-1 do l[j]:= l[j+1] od; l[n]:= h fi end; p(1); cnt end: a:= n-> f(2, 5, n): seq(a(n), n=1..12); # _Alois P. Heinz_, Mar 27 2010 %t A174705 f[m_, M_, n_] := f[m, M, n] = Module[{i, l, p, cnt}, Do[l[i] = i, {i, 1, n}]; cnt = 0; p[t_] := Module[{d, j, h}, If[t == n, d = If[t == 1, m, Abs[l[t] - l[t-1]]]; If [m <= d && d <= M, cnt = cnt+1], For[j = t, j <= n, j++, {l[t], l[j]} = {l[j], l[t]}; d = If[t == 1, m, Abs[l[t] - l[t-1]]]; If [m <= d && d <= M, p[t+1]]]; h = l[t]; For[j = t, j <= n-1, j++, l[j] = l[j+1]]; l[n] = h]]; p[1]; cnt]; a[n_] := f[2, 5, n]; Table[Print["a(", n, ") = ", a[n]]; a[n], {n, 1, 12}] (* _Jean-François Alcover_, Jun 01 2015, after _Alois P. Heinz_ *) %Y A174705 Cf. A003274, A174700, A174701, A174702, A174703, A174704, A174706, A174707, A174708, A185030, A216837. %K A174705 nonn %O A174705 1,4 %A A174705 _W. Edwin Clark_, Mar 27 2010 %E A174705 Edited by _Alois P. Heinz_, Nov 27 2010 %E A174705 a(20)-a(30) from _Andrew Howroyd_, Apr 05 2016 # Content is available under The OEIS End-User License Agreement: http://oeis.org/LICENSE