OFFSET
0,1
COMMENTS
This is the fixed point of the morphism or substitution rules involved in the regular paperfolding sequence and these rules are: map bits: 00 -> 1000, 01 -> 1001, 10 -> 1100, 11 -> 1101.
This sequence contains no fixed points and all terms have an even bit size.
LINKS
Paolo Xausa, Table of n, a(n) for n = 0..10000
Wikipedia, Regular paperfolding sequence
FORMULA
a(n+1) = a(n)+1 for n even.
a(2^k) = ((4^k)(95 + 48(-1)^k) - 8)/15.
EXAMPLE
For n = 216 a(216) = 55752 because:
216 = 3120_4 and
pos | b4 | enc
-----+----+------------
0 | 3 | 31
1 | 1 | 31 21
2 | 2 | 31 21 30
3 | 0 | 31 21 30 20
and 31213020_4 is 55752.
MAPLE
a:= proc(n) option remember; [8, 9, 12, 13]
[irem(n, 4, 'q')+1]+`if`(n<4, 0, 16*a(q))
end:
seq(a(n), n=0..47); # Alois P. Heinz, May 14 2025
MATHEMATICA
A383909[n_] := FromDigits[StringReplace[IntegerString[n, 4], {"0"->"20", "1"->"21", "2"->"30", "3"->"31"}], 4];
Array[A383909, 50, 0] (* Paolo Xausa, May 22 2025 *)
PROG
(Python)
def tobase4(n):
if n == 0: return [0]
d = []
while n > 0:
d.append(n & 3)
n >>= 2
return d[::-1]
def a(n):
B4 = ['20', '21', '30', '31']
return int(''.join(B4[b] for b in tobase4(n)), 4)
print([a(n) for n in range(1, 48)])
(Python)
def A383909(n):
s = ('0' if n.bit_length()&1 else '')+bin(n)[2:] if n else '00'
return int(''.join(('1000', '1001', '1100', '1101')[int(s[i:i+2], 2)] for i in range(0, len(s), 2)), 2) # Chai Wah Wu, May 22 2025
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Darío Clavijo, May 14 2025
STATUS
approved
