OFFSET
0,2
COMMENTS
Numbers n such that when we start scanning bits in the binary expansion of n, from the least to the most significant end, and when we interpret each bit as to a direction which to turn at each vertex (e.g., 0 = left, 1 = right) when traversing the edges of honeycomb lattice, then, when we have consumed all except the most significant 1-bit (which is ignored), we have eventually returned to the same vertex where we started from.
Indexing starts from zero, because a(0) = 1 is a special case, indicating an empty path, which thus ends at the same vertex as where it started from.
If n is a member, then A054429(n) is also a member.
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..18484
Wikipedia, Hexagonal lattice
EXAMPLE
64 ("1000000" in binary) is included, because when we take six turns to the left in the hexagonal lattice, we will reach the same vertex where we started from.
65 ("1000001" in binary) is included, because if we take first turn to the right at some vertex, and then five turns to the left in succession, we also reach the same vertex we started from.
126 ("1111110" in binary) is included, because if we take first turn to the left at some vertex, and then five turns to the right in succession, we also reach the same vertex we started from.
127 ("1111111" in binary) is included, because if we take six turns to the right in the hexagonal lattice, we will reach the same vertex where we started from.
380 ("101111100" in binary) is included, because it traces a path, where we first turn left from the starting vertex, then circumambulate a hexagon clockwise, after which we come back to the starting vertex. Note that the vertex next to the starting vertex is visited twice.
PROG
(Scheme, with Antti Karttunen's IntSeq-library)
(define A255570 (MATCHING-POS 0 1 isA255570?))
(define (isA255570? n) (let loop ((n n) (x 0) (y 0) (phase 0)) (cond ((= 1 n) (and (zero? x) (zero? y))) (else (let* ((d (modulo n 2)) (newphase (modulo (+ phase d d -1) 6))) (loop (/ (- n d) 2) (+ x (x-delta newphase)) (+ y (y-delta newphase)) newphase))))))
(define (newphase p d) (modulo (+ p d d -1) 6))
(define (x-delta phase) (* (- (* 2 (floor->exact (/ phase 3))) 1) (- (modulo phase 3) 1)))
(define (y-delta phase) (* (- 1 (* 2 (floor->exact (/ phase 3)))) (floor->exact (/ (+ 1 (modulo phase 3)) 2))))
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Apr 13 2015
STATUS
approved