login
If n (in base 10) is d_1 d_2 ... d_k then a(n) = Sum_{i = 1..[k/2] } |d_i - d_{k-i+1}|.
11

%I #29 Apr 03 2020 17:55:09

%S 0,0,0,0,0,0,0,0,0,0,1,0,1,2,3,4,5,6,7,8,2,1,0,1,2,3,4,5,6,7,3,2,1,0,

%T 1,2,3,4,5,6,4,3,2,1,0,1,2,3,4,5,5,4,3,2,1,0,1,2,3,4,6,5,4,3,2,1,0,1,

%U 2,3,7,6,5,4,3,2,1,0,1,2,8,7,6,5,4,3,2,1,0,1,9,8,7,6,5,4,3,2,1,0,1,0,1,2,3

%N If n (in base 10) is d_1 d_2 ... d_k then a(n) = Sum_{i = 1..[k/2] } |d_i - d_{k-i+1}|.

%C Might be called the Palindromic Deviation (or PD(n)) of n, since it measures how far n is from being a palindrome. - _W. W. Kokko_, Mar 13 2013

%C a(A002113(n)) = 0; a(A029742(n)) > 0; A136522(n) = A000007(a(n)). - _Reinhard Zumkeller_, Sep 18 2013

%H N. J. A. Sloane, <a href="/A064834/b064834.txt">Table of n, a(n) for n = 0..10000</a>

%H <a href="/index/Pac#palindromes">Index entries for sequences related to palindromes</a>

%e a(456) = | 4 - 6 | = 2, a(4567) = | 4 - 7 | + | 5 - 6 | = 4.

%p f:=proc(n)

%p local t1,t2,i;

%p t1:=convert(n,base,10);

%p t2:=nops(t1);

%p add( abs(t1[i]-t1[t2+1-i]),i=1..floor(t2/2) );

%p end;

%p [seq(f(n),n=0..120)]; # _N. J. A. Sloane_, Mar 24 2013

%t f[n_] := (k = IntegerDigits[n]; l = Length[k]; Sum[ Abs[ k[[i]] - k[[l - i + 1]]], {i, 1, Floor[l/2] } ] ); Table[ f[n], {n, 0, 100} ]

%o (Haskell)

%o a064834 n = sum $ take (length nds `div` 2) $

%o map abs $ zipWith (-) nds $ reverse nds

%o where nds = a031298_row n

%o -- _Reinhard Zumkeller_, Sep 18 2013

%o (Python)

%o from sympy import floor, ceiling

%o def A064834(n):

%o x, y = str(n), 0

%o lx2 = len(x)/2

%o for a,b in zip(x[:floor(lx2)],x[:ceiling(lx2)-1:-1]):

%o y += abs(int(a)-int(b))

%o return y

%o # _Chai Wah Wu_, Aug 09 2014

%Y Cf. A037904, A040163, A064844.

%Y Cf. A031298, A037888.

%K nonn,base,easy

%O 0,14

%A _N. J. A. Sloane_, Oct 25 2001

%E More terms from _Vladeta Jovovic_, _Matthew Conroy_ and _Robert G. Wilson v_, Oct 26 2001