This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A129118 #24 May 21 2020 09:57:51 %S A129118 0,1,2,10,48,295,2068,16654,150382,1508500,16631696,199966907, %T A129118 2603709640,36501212971,548150650582,8779185528284,149376644391508, %U A129118 2690852138104504,51161190374132154,1023850096381041159,21512688329462044264 %N A129118 For each permutation p of {1,2,...,n} define minabsjump(p) = min(|p(i) - i|, 1<=i<=n); a(n) is the sum of minabsjumps of all p. %F A129118 a(n) = Sum_{k=1..floor(n/2)} k * A299789(n,k). - _Alois P. Heinz_, Jan 21 2019 %p A129118 n:=8; with(combinat); P:=permute(n); ct:= 0; for j to factorial(n) do ct:= ct+min(seq(abs(P[j][i]-i),i=1..n)) end do: ct; # yields a(n) for the specified n - _Emeric Deutsch_, Aug 24 2007 %p A129118 # second Maple program: %p A129118 b:= proc(s) option remember; (n-> `if`(n=1, x^(s[]-1), add((p-> %p A129118 add(coeff(p, x, i)*x^min(i, abs(n-j)), i=0..degree(p)))( %p A129118 b(s minus {j})), j=s)))(nops(s)) %p A129118 end: %p A129118 a:= n-> (p-> add(coeff(p, x, i)*i, i=1..n-1))(b({$1..n})): %p A129118 seq(a(n), n=1..15); # _Alois P. Heinz_, Jan 21 2019 %t A129118 b[s_] := b[s] = Function[n, If[n == 1, x^(s - 1), Sum[Function[p, Sum[ SeriesCoefficient[p, {x, 0, i}]*x^Min[i, Abs[n - j]], {i, 0, Exponent[p, x]}]][b[s ~Complement~ {j}]], {j, s}]]][Length[s]] // Expand; %t A129118 a[n_] := a[n] = If[n == 1, 0, Function[p, Sum[SeriesCoefficient[p, {x, 0, i}]*i, {i, 1, n - 1}]][b[Range[n]][[1]]]]; %t A129118 Table[Print[n, " ", a[n]]; a[n], {n, 1, 12}] (* _Jean-François Alcover_, May 21 2020, after 2nd Maple program *) %o A129118 (C++) #include <iostream> #include <vector> #include <algorithm> using namespace std; inline int mabsj(const vector<int> & s) { const int n = s.size() ; int mi =n ; for(int i=0; i<n; i++) { const int thisdiff = abs(s[i]-i-1) ; if ( thisdiff < mi ) mi=thisdiff ; } return mi ; } int main(int argc, char *argv[]) { for(int n=1 ;;n++) { vector<int> s; for(int i=1;i<=n;i++) s.push_back(i) ; unsigned long long resul=0 ; do { resul += mabsj(s) ; } while( next_permutation(s.begin(),s.end()) ) ; cout << n << " " << resul << endl ; } return 0 ; } /* _R. J. Mathar_, Nov 01 2007 */ %Y A129118 Cf. A130153, A018927, A299789. %K A129118 more,nonn %O A129118 1,3 %A A129118 _Emeric Deutsch_, _Vladeta Jovovic_, Jun 07 2007 %E A129118 One more term from _Emeric Deutsch_, Aug 24 2007 %E A129118 a(11)-a(13) from _R. J. Mathar_, Nov 01 2007 %E A129118 a(14) from _Donovan Johnson_, Sep 24 2010 %E A129118 a(15)-a(21) from _Alois P. Heinz_, Jan 21 2019