OFFSET
0,2
COMMENTS
Numbers n such that when we start scanning bits in the binary expansion of n, from the most to the least 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 the bits, we have eventually returned to the same vertex where we started from and none of the other vertices have been visited twice.
Indexing starts from zero, because a(0) = 0 is a special case, indicating an empty path, which certainly ends at the same vertex as where it starts from. For other cases, we always take first a right turn, because the most significant bit is always 1.
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..13242
Wikipedia, Hexagonal lattice
EXAMPLE
32 ("100000" 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 will reach the same vertex where we started from.
63 ("111111" in binary) is included, because when we take six turns to the right in the hexagonal lattice, we will reach the same vertex where we started from.
528 ("1000010000" in binary) is included, because it traces the edges of two adjacent hexagons, returning to the same vertex where the path started from, which is the other of the two vertices shared by those hexagons.
PROG
(Scheme, with Antti Karttunen's IntSeq-library)
(define A255561 (MATCHING-POS 0 0 (COMPOSE isA255561bitlist? bits->list)))
(define (bits->list n) (reverse! (bits-reversed->list n)))
(define (bits-reversed->list n) (if (zero? n) (list) (cons (modulo n 2) (bits-reversed->list (floor->exact (/ n 2))))))
(define (isA255561bitlist? bitlist) (let loop ((bitlist bitlist) (x 0) (y 0) (phase 0) (vv (list))) (cond ((null? bitlist) (and (zero? x) (zero? y))) ((member (cons x y) vv) #f) (else (let* ((d (first bitlist)) (newphase (modulo (+ phase d d -1) 6))) (loop (cdr bitlist) (+ x (x-delta newphase)) (+ y (y-delta newphase)) newphase (cons (cons x y) vv)))))))
(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