A303548 For any n > 0 and h > 0, let d_h(n) be the distance from n to the nearest number with Hamming weight at most h; a(n) = Sum_{i > 0} d_i(n).
0, 0, 1, 0, 1, 2, 2, 0, 1, 2, 4, 4, 4, 4, 3, 0, 1, 2, 4, 4, 6, 8, 9, 8, 8, 8, 9, 8, 7, 6, 4, 0, 1, 2, 4, 4, 6, 8, 9, 8, 10, 12, 15, 16, 17, 18, 18, 16, 16, 16, 17, 16, 17, 18, 18, 16, 15, 14, 14, 12, 10, 8, 5, 0, 1, 2, 4, 4, 6, 8, 9, 8, 10, 12, 15, 16, 17, 18
Offset: 1
Examples
For n = 42: - d_1(n) = |42 - 32| = 10, - d_2(n) = |42 - 40| = 2, - d_h(n) = 0 for any h >= 3, - hence a(42) = 10 + 2 = 12.
Links
- Rémy Sigrist, Table of n, a(n) for n = 1..10000
- Rémy Sigrist, Colored pin plot of the first 3 * 512 terms (where the color is function of the number h in the term d_h(n))
- Index entries for sequences related to distance to nearest element of some set
Programs
-
PARI
a(n) = my (v=0, h=hamming weight(n)); for (d=0, oo, my (o=min(hamming weight(n-d), hamming weight(n+d))); if (o
Comments