login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A080116 Characteristic function of A014486. a(n) = 1 if n's binary expansion is totally balanced, otherwise zero. 6

%I #26 Sep 20 2022 09:24:07

%S 1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

%T 0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,

%U 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

%N Characteristic function of A014486. a(n) = 1 if n's binary expansion is totally balanced, otherwise zero.

%C a(n) = 1 if the binary representation of n forms a valid Dyck path, or equally, a well-formed parenthesization when 1's are converted to left and 0's to right parentheses (that is, when A007088(n) is in A063171), and 0 otherwise. - _Antti Karttunen_, Aug 23 2019

%H Antti Karttunen, <a href="/A080116/b080116.txt">Table of n, a(n) for n = 0..65537</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%H <a href="/index/Ch#char_fns">Index entries for characteristic functions</a>

%H <a href="/index/Par#parens">Index entries for sequences related to parenthesizing</a>

%e 0 stands for an empty parenthesization, thus a(0) = 1.

%e 2 has binary expansion "10", which corresponds with "()", thus a(2) = 1.

%e 3 has binary expansion "11", but "((" is not a well-formed parenthesization, thus a(3) = 0.

%e 10 has binary expansion "1010", corresponding with a well-formed parenthesization "()()", thus a(10) = 1.

%e 38 has binary expansion "100110", but "())(()" is not a well-formed parenthesization, thus a(38) = 0.

%p A080116 := proc(n) local c,lev; lev := 0; c := n; while(c > 0) do lev := lev + (-1)^c; c := floor(c/2); if(lev < 0) then RETURN(0); fi; od; if(lev > 0) then RETURN(0); else RETURN(1); fi; end;

%t A080116[n_] := (lev = 0; c = n; While[c > 0, lev = lev + (-1)^c; c = Floor[c/2]; If[lev < 0, Return[0]]]; If[lev > 0, Return[0], Return[1]]); Table[A080116[n], {n, 0, 104}] (* _Jean-François Alcover_, Jul 24 2013, translated from Maple *)

%o (Sage)

%o def A080116(n) :

%o lev = 0

%o while n > 0 :

%o lev += (-1)^n

%o if lev < 0: return 0

%o n = n//2

%o return 0 if lev > 0 else 1

%o [A080116(n) for n in (0..104)] # _Peter Luschny_, Aug 09 2012

%o (PARI) A080116(n) = { my(k=0); while(n, k += (-1)^n; n >>= 1; if(k<0, return(0))); (0==k); }; \\ _Antti Karttunen_, Aug 23 2019

%Y Cf. A014486, A063171, A080110, A080111, A080300, A080301.

%K nonn,base

%O 0,1

%A _Antti Karttunen_, Feb 11 2003

%E Examples added by _Antti Karttunen_, Aug 23 2019

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 24 13:24 EDT 2024. Contains 371955 sequences. (Running on oeis4.)