login
A374849
In the binary expansion of n: collapse bits from most to least significant 10 -> 1, 01 -> 0, 00 -> nothing, 11 -> nothing.
1
0, 1, 0, 1, 1, 0, 0, 1, 2, 3, 1, 0, 0, 1, 0, 1, 1, 2, 2, 3, 3, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 2, 3, 1, 2, 4, 5, 2, 3, 6, 7, 3, 1, 2, 3, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 2, 3, 1, 0, 0, 1, 0, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 2, 2, 3, 3, 6, 6, 7, 7, 3, 3
OFFSET
1,9
COMMENTS
This is essentialy the Von Neumann biased to fair coin extractor.
a(n) = 0 if the collapse results in no bits.
If the bit size of n is odd then the least significant bit is ignored.
LINKS
EXAMPLE
For n = 27983, the bits of n collapse as
n = binary 11 01 10 10 10 01 11 1
a(n) = binary 0 1 1 1 0 = 14
MATHEMATICA
A374849[n_] := FromDigits[StringReplace[IntegerString[n, 2], {"01"->"0", "10"->"1", Repeated[_, 2]->""}], 2];
Array[A374849, 100] (* Paolo Xausa, Oct 01 2024 *)
PROG
(Python)
def a(n):
e, B = "", bin(n)[2:]
for i in range(0, len(B), 2):
if B[i:i+2] == "10": e += "1"
if B[i:i+2] == "01": e += "0"
if e == '': return 0
return int(e, 2)
print([a(n) for n in range(1, 70)])
CROSSREFS
Sequence in context: A070078 A054438 A261015 * A286584 A174947 A010341
KEYWORD
nonn,base,easy
AUTHOR
Darío Clavijo, Sep 16 2024
STATUS
approved