A297330 Total variation of base-10 digits of n; see Comments.
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, 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, 2, 3, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 8, 7, 6, 5, 4, 3, 2
Offset: 1
Examples
13684632 has DV = 8-4 + 6-3 + 3-2 = 8 and has UV = 3-1 + 6-3 + 8-6 + 6-4 = 9, so that a(13684632) = DV + UV = 17.
Links
- Clark Kimberling, Table of n, a(n) for n = 1..10000
Programs
-
Maple
f:= proc(n) local L,i; L:= convert(n,base,10); add(abs(L[i+1]-L[i]),i=1..nops(L)-1) end proc: map(f, [$1..100]); # Robert Israel, Feb 04 2018 # alternative A297330 := proc(n) A037860(n)+A037851(n) ; end proc: # R. J. Mathar, Sep 27 2021
-
Mathematica
b = 10; z = 120; t = Table[Total@Flatten@Map[Abs@Differences@# &, Partition[ IntegerDigits[n, b], 2, 1]], {n, z}] (* after Michael De Vlieger, e.g. A037834 *)
-
Python
def A297330(n): s = str(n) return sum(abs(int(s[i])-int(s[i+1])) for i in range(len(s)-1)) # Chai Wah Wu, May 31 2022
Comments