A249919 Number of LCD (liquid-crystal display) segments needed to display n in binary.
6, 2, 8, 4, 14, 10, 10, 6, 20, 16, 16, 12, 16, 12, 12, 8, 26, 22, 22, 18, 22, 18, 18, 14, 22, 18, 18, 14, 18, 14, 14, 10, 32, 28, 28, 24, 28, 24, 24, 20, 28, 24, 24, 20, 24, 20, 20, 16, 28, 24, 24, 20, 24, 20, 20, 16, 24, 20, 20, 16, 20, 16, 16, 12, 38, 34, 34, 30, 34, 30, 30, 26, 34, 30, 30, 26, 30, 26, 26
Offset: 0
Examples
For n = 4, 4 = 100_2. So, a(4) = 2 + 6 + 6 = 14. - _Indranil Ghosh_, Feb 02 2017
Links
- Indranil Ghosh, Table of n, a(n) for n = 0..32768
Programs
-
C
// Input: n (no negative offset/term number), Output: a(n) int A249919 (int n) { int m=0, r=0; if (n) { while (n!=1) { m=n&1; //equivalent to m=n%2; n=n>>1; //equivalent to n/=2; if (m) { r+=2; } else { r+=6; } } r+=2; } else { r+=6; } return r; } // Arlu Genesis A. Padilla, Jun 18 2015
-
Mathematica
f[n_] := Total[{2, 6}*(Count[ IntegerDigits[n, 2], #] & /@ {1, 0})]; Array[f, 79, 0] (* Robert G. Wilson v, Jul 26 2015 *)
-
PARI
a(n)=if(n==0, 6, 6*#binary(n) - 4*hammingweight(n)); \\ Charles R Greathouse IV, Feb 28 2015
-
Python
def A249919(n): x=bin(n)[2:] s=0 for i in x: s+=[6,2][int(i)] return s # Indranil Ghosh, Feb 02 2017
Formula
The formulas below do not include a(0)=6:
a(2^(n-1)) = 2 + 6(n-1).
a((2^n)-1) = 2n.
a(x) = a(2^(n+1) + (2^n)-1) = a(2^(n+2)-1) + 4.
a(y) = a(2^(n+1) + (2^n)) = a(2^(n+1)) - 4.
a(x - u) + 6 = a(x - u + 2^(n+1)).
a(y + u) + 6 = a(y + u + 2^(n+1)).
a(2^(n+1)) + a(2^(n+2)-1) = a(x - u) + a(y + u).
where n=1, 2, ...
and u=0, ..., (2^n)-2.
Comments