%I #21 Jun 18 2015 06:08:12
%S 0,32,63,528,545,578,644,759,776,891,957,990,1007,2184,2321,2594,3003,
%T 3140,3549,3822,3959,8481,8514,8580,8771,8772,8837,8969,9264,9288,
%U 9350,9353,9482,9746,10167,10320,10337,10385,10508,10514,10772,11223,11300,11739,11751,11997,12093,12126,12143,12432,12449,12482,12578,12824,12836,13275
%N Numbers whose binary representation traces a non-selfcrossing circuit in the honeycomb lattice when each one of its bits, from the most significant to the least significant, is interpreted as a direction to proceed at each vertex.
%C 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.
%C 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.
%H Antti Karttunen, <a href="/A255561/b255561.txt">Table of n, a(n) for n = 0..13242</a>
%H Wikipedia, <a href="http://en.wikipedia.org/wiki/Honeycomb_lattice">Hexagonal lattice</a>
%e 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.
%e 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.
%e 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.
%o (Scheme, with _Antti Karttunen_'s IntSeq-library)
%o (define A255561 (MATCHING-POS 0 0 (COMPOSE isA255561bitlist? bits->list)))
%o (define (bits->list n) (reverse! (bits-reversed->list n)))
%o (define (bits-reversed->list n) (if (zero? n) (list) (cons (modulo n 2) (bits-reversed->list (floor->exact (/ n 2))))))
%o (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)))))))
%o (define (newphase p d) (modulo (+ p d d -1) 6))
%o (define (x-delta phase) (* (- (* 2 (floor->exact (/ phase 3))) 1) (- (modulo phase 3) 1)))
%o (define (y-delta phase) (* (- 1 (* 2 (floor->exact (/ phase 3)))) (floor->exact (/ (+ 1 (modulo phase 3)) 2))))
%Y Cf. A014486, A255571.
%Y Subsequence: A258004.
%K nonn,base
%O 0,2
%A _Antti Karttunen_, Apr 13 2015