A257265 Distance to n from a leaf nearest to n in the binary beanstalk.
2, 1, 0, 1, 1, 0, 0, 1, 2, 0, 1, 1, 0, 0, 0, 1, 2, 0, 1, 2, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 2, 0, 1, 2, 0, 0, 1, 1, 0, 1, 2, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 2, 0, 1, 2, 0, 0, 1, 1, 0, 1, 2, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 1, 0, 0, 0, 2, 1, 0, 2, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2
Offset: 0
Keywords
Examples
For 0, the nearest leaf is 2, as when we start from 2, and always subtract the binary weight, A000120, we have: 2 - A000120(2) = A011371(2) = 1, and A011371(1) = 0, thus it takes two steps to get to 0, and there are no other terms of A055938 from which it would take fewer steps), so a(0) = 2, and also a(1) = 1, because it's one step nearer to 2. a(2) = 0, because 2 is one of the terms of A055938. a(8) = 2, because 12, 13 and 14 are the three nearest leaves to 8, and A011371(12) = A011371(13) = 10, A011371(14) = 11, A011371(10) = A011371(11) = 8 (thus it takes two iterations of A011371 to reach 8 from any of those three leaves) and there are no leaves nearer. Please see also Paul Tek's illustration.
Links
- Antti Karttunen, Table of n, a(n) for n = 0..16384
- Ela, peano
- Haskell Wiki, Peano numbers
- Paul Tek, Illustration of how natural numbers in range 0 .. 133 are organized as a binary tree in the binary beanstalk
Crossrefs
Programs
-
Haskell
a257265 = length . us where us n = if a079559 n == 0 then [] else () : zipWith (const $ const ()) (us $ a213723 n) (us $ a213724 n) -- Reinhard Zumkeller, May 03 2015
-
Scheme
;; Do a breadth-first search over the descendants, which are at each step of iteration sorted by their distance from the starting node. (define (A257265 n) (let loop ((descendants (list (cons 0 n)))) (let ((dist (caar descendants)) (node (cdar descendants))) (cond ((zero? (A079559 node)) dist) (else (loop (sort (append (list (cons (+ 1 dist) (A213724 node)) (cons (+ 1 dist) (A213723 node))) (cdr descendants)) (lambda (a b) (< (car a) (car b))))))))))
Comments