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”).

A137843
Define S(1) = {1}, S(n+1) = S(n) U S(n) if a(n) is even, S(n+1) = S(n) U (n+1) U S(n) if a(n) is odd. Sequence {a(n), n >= 1} is limit as n approaches infinity of S(n). (U represents concatenation.).
4
1, 2, 1, 1, 2, 1, 4, 1, 2, 1, 1, 2, 1, 5, 1, 2, 1, 1, 2, 1, 4, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 4, 1, 2, 1, 1, 2, 1, 5, 1, 2, 1, 1, 2, 1, 4, 1, 2, 1, 1, 2, 1, 7, 1, 2, 1, 1, 2, 1, 4, 1, 2, 1, 1, 2, 1, 5, 1, 2, 1, 1, 2, 1, 4, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 4, 1, 2, 1, 1, 2, 1, 5, 1, 2, 1, 1, 2, 1, 4, 1, 2, 1, 1, 2, 1
OFFSET
1,2
EXAMPLE
S(1) = {1}.
S(2) = {1,2,1}, because a(1) = 1, which is odd.
S(3) = {1,2,1,1,2,1}, because a(2) = 2, which is even.
S(4) = {1,2,1,1,2,1,4,1,2,1,1,2,1}, as a(3) is odd.
S(5) = {1,2,1,1,2,1,4,1,2,1,1,2,1,5,1,2,1,1,2,1,4,1,2,1,1,2,1}, as a(4) is odd.
Etc.
PROG
(Scheme, with memoization-macro definec)
(definec (A137843 n) (if (= 1 n) n (let ((k (let loop ((j 1)) (if (>= (A291753 j) n) j (loop (+ 1 j)))))) (cond ((= (+ 1 (A291753 (- k 1))) n) (if (odd? (A137843 (- k 1))) k 1)) (else (A137843 (- n (+ (A291753 (- k 1)) (A000035 (A137843 (- k 1)))))))))))
(definec (A291753 n) (if (= 1 n) 1 (+ (* 2 (A291753 (- n 1))) (A000035 (A137843 (- n 1))))))
(define (A000035 n) (modulo n 2))
;; Antti Karttunen, Aug 31 2017
CROSSREFS
Cf. A096055, A137844 (variants of the same theme).
Cf. A291753 (the length of stage n).
Sequence in context: A266685 A272620 A304080 * A130194 A113926 A276376
KEYWORD
easy,nonn
AUTHOR
Leroy Quet, Feb 13 2008
EXTENSIONS
More terms from Antti Karttunen, Aug 31 2017
STATUS
approved