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
Paolo Xausa, Table of n, a(n) for n = 1..10000
Wikipedia, Fair coin.
Wikipedia, Randomness extractor.
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
KEYWORD
nonn,base,easy
AUTHOR
Darío Clavijo, Sep 16 2024
STATUS
approved