login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A254104
Permutation of natural numbers: a(0) = 0, a(3n) = 1 + 2*a(2n - 1), a(3n+1) = 1 + 2*a(2n), a(3n+2) = 2*a(n+1).
10
0, 1, 2, 3, 5, 4, 7, 11, 6, 9, 15, 10, 23, 13, 8, 19, 31, 14, 21, 47, 22, 27, 17, 12, 39, 63, 18, 29, 43, 30, 95, 45, 20, 55, 35, 46, 25, 79, 26, 127, 37, 16, 59, 87, 38, 61, 191, 62, 91, 41, 28, 111, 71, 42, 93, 51, 94, 159, 53, 44, 255, 75, 54, 33, 119, 34, 175, 77, 24, 123, 383, 78, 125, 183, 126, 83, 57, 36, 223, 143, 58, 85, 187, 86, 103, 189, 60
OFFSET
0,3
FORMULA
a(0) = 0, a(3n) = 1 + 2*a(2n - 1), a(3n+1) = 1 + 2*a(2n), a(3n+2) = 2*a(n+1).
Other identities:
a(A007051(n)) = 2^n for all n >= 0. [A property shared with A064216.]
PROG
(Scheme, with memoizing macro definec)
(definec (A254104 n) (cond ((< n 1) n) ((= 2 (modulo n 3)) (* 2 (A254104 (/ (+ n 1) 3)))) (else (+ 1 (* 2 (A254104 (+ -1 (inv_for_A032766 n))))))))
(define (inv_for_A032766 n) (+ (* 2 (floor->exact (/ n 3))) (modulo n 3)))
(Python)
def a(n):
if n==0: return 0
if n%3==0: return 1 + 2*a(2*n//3 - 1)
elif n%3==1: return 1 + 2*a(2*(n - 1)//3)
else: return 2*a((n - 2)//3 + 1)
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Jan 25 2015
STATUS
approved

  NODES
orte 1
see 1
Story 1