%I #43 Jun 24 2022 19:55:17
%S 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,
%T 18,18,14,18,14,14,10,32,28,28,24,28,24,24,20,28,24,24,20,24,20,20,16,
%U 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
%N Number of LCD (liquid-crystal display) segments needed to display n in binary.
%C The "LCD" refers to how 0 and 1 are displayed, such that zero is represented with 6 lines, and one is represented with 2 lines:
%C _
%C | | |
%C |_| and |
%H Indranil Ghosh, <a href="/A249919/b249919.txt">Table of n, a(n) for n = 0..32768</a>
%F The formulas below do not include a(0)=6:
%F a(2^(n-1)) = 2 + 6(n-1).
%F a((2^n)-1) = 2n.
%F a(x) = a(2^(n+1) + (2^n)-1) = a(2^(n+2)-1) + 4.
%F a(y) = a(2^(n+1) + (2^n)) = a(2^(n+1)) - 4.
%F a(x - u) + 6 = a(x - u + 2^(n+1)).
%F a(y + u) + 6 = a(y + u + 2^(n+1)).
%F a(2^(n+1)) + a(2^(n+2)-1) = a(x - u) + a(y + u).
%F where n=1, 2, ...
%F and u=0, ..., (2^n)-2.
%F a(n) = A010371(A007088(n)). - _Michel Marcus_, Aug 01 2015
%e For n = 4, 4 = 100_2. So, a(4) = 2 + 6 + 6 = 14. - _Indranil Ghosh_, Feb 02 2017
%t f[n_] := Total[{2, 6}*(Count[ IntegerDigits[n, 2], #] & /@ {1, 0})]; Array[f, 79, 0] (* _Robert G. Wilson v_, Jul 26 2015 *)
%o (PARI) a(n)=if(n==0, 6, 6*#binary(n) - 4*hammingweight(n)); \\ _Charles R Greathouse IV_, Feb 28 2015
%o (C)
%o // Input: n (no negative offset/term number), Output: a(n)
%o int A249919 (int n) {
%o int m=0, r=0;
%o if (n) {
%o while (n!=1) {
%o m=n&1; //equivalent to m=n%2;
%o n=n>>1; //equivalent to n/=2;
%o if (m) {
%o r+=2;
%o } else {
%o r+=6;
%o }
%o }
%o r+=2;
%o } else {
%o r+=6;
%o }
%o return r;
%o }
%o // _Arlu Genesis A. Padilla_, Jun 18 2015
%o (Python)
%o def A249919(n):
%o x=bin(n)[2:]
%o s=0
%o for i in x:
%o s+=[6,2][int(i)]
%o return s # _Indranil Ghosh_, Feb 02 2017
%Y Cf. A007088, A010371, A074458.
%K easy,nonn,base
%O 0,1
%A _Arlu Genesis A. Padilla_, Jan 14 2015