OFFSET
0,3
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..16384
FORMULA
a(0) = 0; a(1) = 1;
otherwise set prev = a(n-1);
else a(n) = A213724(prev);
otherwise,
a(n) = {the first unvisited node of binary beanstalk tree found when we backtrack out of a finite branch just traversed in depth-first order}.
Other identities and observations:
If a(n-1) is an even term of A055938 then a(n) = a(n-1)+1.
EXAMPLE
Please look at Paul Tek's illustration: We start at root, 0, go up to 1, visit its left child 2 (which is a leaf), before proceeding the infinite trunk (A179016) to 3, then visit first the leaf 5 at the right hand side, before proceeding the infinite trunk to 4, then visit the leaf 6 at the left hand side, before proceeding the infinite trunk right to 7, from which we first visit the leaf 9 at the right hand side, before proceeding the infinite trunk to 8 at the left hand side. Thus we have ten initial terms of the sequence: 0, 1, 2, 3, 5, 4, 6, 7, 9, 8, ...
From 8 we proceed first to the left 10, because it is not a part of the infinite trunk, and we traverse a finite side-tree ("tendril") of three nodes in order 10, 12, 13, only after which we proceed the infinite trunk to the right, to 11, thus we have the next four terms of the sequence 10, 12, 13, 11.
PROG
(Scheme, with defineperm1-macro from Antti Karttunen's IntSeq-library)
(defineperm1 (A257676 n) (if (<= n 1) n (let ((prev (A257676 (- n 1)))) (cond ((= 1 (A213719 prev)) (if (zero? (A213719 (A213723 prev))) (A213723 prev) (A213724 prev))) ((not (zero? (A213723 prev))) (A213723 prev)) ((not (zero? (A213724 prev))) (A213724 prev)) (else (let loop ((prev prev) (back (A011371 prev))) (cond ((= 1 (A213719 back)) (if (zero? (A213719 (A213723 back))) (A213724 back) (A213723 back))) ((and (even? prev) (not (zero? (A213724 back)))) (A213724 back)) (else (loop back (A011371 back))))))))))
;; Please see the attached text file for the same code better indented and documented.
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, May 04 2015
STATUS
approved