reviewed
approved
reviewed
approved
proposed
reviewed
editing
proposed
Antti Karttunen, <a href="/A226062/b226062_1.txt">Table of n, a(n) for n = 0..8191</a>
proposed
approved
editing
proposed
Antti Karttunen, <a href="/A129594/a129594_1.txt">Python-program for computing this and related sequences.</a>
(Python)
def A226062(n):
'''Bulgarian solitaire operation applied to the partition encoded in the runlengths of binary expansion of n.'''
return(ascpart_to_binexp(bulgarian_operation(binexp_to_ascpart(n))))
def bulgarian_operation(ap):
'''Apply Bulgarian Solitaire operation to unordered partition: decrement one from each part and add a new part of the same size as there were originally parts.'''
if([] == ap): return(ap)
np = [len(ap)]+[(part-1) for part in ap if part != 1]
np.sort() # Sort back into nondecreasing order.
return(np)
# Compare the next definition with the Python-prodecure for A227183:
def binexp_to_ascpart(n):
'''Convert n according to its binary expansion to a unique unordered partition, listed in nondecreasing order.'''
ap = []
b = n%2
i = 1
while (n != 0):
n >>= 1
if ((n%2) == b):
i += 1
else:
b = n%2
ap += [i]
return(ap)
def ascpart_to_binexp(ap):
'''Convert an unordered partition (listed in nondecreasing order) to an integer which encodes that partition.'''
n = 0
prevpart = 1
parity = (len(ap)%2)
p2 = 1
for part in ap:
runlen = (part - prevpart)+1
if (0 != parity): n += (((2**runlen)-1) * p2)
p2 <<= runlen
prevpart = part
parity = 1-parity
return(n)
proposed
editing
editing
proposed