OFFSET
0,3
COMMENTS
This sequence can be represented as a binary tree. Each child to the left is obtained by multiplying the parent by three and subtracting one, and each child to the right is obtained by adding one to parent, multiplying by three, and then halving the result (discarding a possible remainder):
0
|
...................1...................
2 3
5......../ \........4 8......../ \........6
/ \ / \ / \ / \
/ \ / \ / \ / \
/ \ / \ / \ / \
14 9 11 7 23 13 17 10
41 22 26 15 32 18 20 12 68 36 38 21 50 27 29 16
etc.
LINKS
FORMULA
PROG
(Scheme, with memoizing macro definec)
;; First a stand-alone version for MIT/GNU Scheme:
(definec (A254103 n) (cond ((zero? n) n) ((even? n) (+ -1 (* 3 (A254103 (/ n 2))))) (else (floor->exact (/ (* 3 (+ 1 (A254103 (/ (- n 1) 2)))) 2)))))
(definec (A254103 n) (cond ((< n 1) n) ((even? n) (A016789 (- (A254103 (/ n 2)) 1))) (else (A032766 (+ 1 (A254103 (/ (- n 1) 2))))))) ;; Above represented with A-numbers.
(Python)
def a(n):
if n==0: return 0
if n%2==0: return 3*a(n//2) - 1
else: return int((3*(1 + a((n - 1)//2)))/2)
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Jan 25 2015
STATUS
approved