login
The stripe enumeration of N X N where N = {0, 1, 2, ...}, also called boustrophedonic Cantor enumeration. Terms are interleaved x and y coordinates.
8

%I #32 May 22 2022 01:52:12

%S 0,0,0,1,1,0,2,0,1,1,0,2,0,3,1,2,2,1,3,0,4,0,3,1,2,2,1,3,0,4,0,5,1,4,

%T 2,3,3,2,4,1,5,0,6,0,5,1,4,2,3,3,2,4,1,5,0,6,0,7,1,6,2,5,3,4,4,3,5,2,

%U 6,1,7,0,8,0,7,1,6,2,5,3,4,4,3,5,2,6,1

%N The stripe enumeration of N X N where N = {0, 1, 2, ...}, also called boustrophedonic Cantor enumeration. Terms are interleaved x and y coordinates.

%C If (x, y) and (x', y') are adjacent points on the trajectory of the map then max(|x - x'|, |y - y'|) is always 1 whereas for the Cantor enumeration this quantity can become arbitrarily large. In this sense our boustrophedonic variant is continuous whereas Cantor's realization is not.

%C We implemented the recursive enumeration as a state machine with two states to avoid the evaluation of the square root function.

%C The inverse function, computing n for given (x, y), is (x + y)*(x + y + 1)/2 + p where p = x if x - y is odd and y otherwise.

%H Peter Luschny, <a href="/A319571/b319571.txt">Table of n, a(n) for n = 0..10000</a>

%H Georg Cantor, <a href="http://gdz.sub.uni-goettingen.de/dms/resolveppn/?PPN=GDZPPN002156806">Ein Beitrag zur Mannigfaltigkeitslehre</a>, Journal für die reine und angewandte Mathematik 84 (1878), 242-258.

%H Steven Pigeon, <a href="https://hbfs.wordpress.com/2018/07/31/moeud/">Mœud</a>, 2018.

%H A. L. Rosenberg, <a href="https://doi.org/10.1145/321850.321861">Allocating storage for extendible Arrays</a>, J. ACM, vol 21(4), 1974, p. 652-670.

%H <a href="/index/Con#coordinates_2D_curves">Index entries for sequences related to coordinates of 2D curves</a>

%e The map starts, for n = 0, 1, 2, ...

%e (0, 0), (0, 1), (1, 0), (2, 0), (1, 1), (0, 2), (0, 3), (1, 2), (2, 1), (3, 0),

%e (4, 0), (3, 1), (2, 2), (1, 3), (0, 4), (0, 5), (1, 4), (2, 3), (3, 2), (4, 1),

%e (5, 0), (6, 0), (5, 1), (4, 2), (3, 3), (2, 4), (1, 5), (0, 6), (0, 7), (1, 6),

%e (2, 5), (3, 4), (4, 3), (5, 2), (6, 1), (7, 0), ...

%e The enumeration can be seen as diagonal stripes layering on the origin:

%e (0, 0),

%e (0, 1), (1, 0),

%e (2, 0), (1, 1), (0, 2),

%e (0, 3), (1, 2), (2, 1), (3, 0),

%e (4, 0), (3, 1), (2, 2), (1, 3), (0, 4),

%e (0, 5), (1, 4), (2, 3), (3, 2), (4, 1), (5, 0),

%e (6, 0), (5, 1), (4, 2), (3, 3), (2, 4), (1, 5), (0, 6),

%e (0, 7), (1, 6), (2, 5), (3, 4), (4, 3), (5, 2), (6, 1), (7, 0)

%o (Julia)

%o function A319571(n)

%o k, r = divrem(n, 2)

%o d = div(isqrt(8k+1) - 1, 2)

%o s = k - div(d*(d + 1), 2)

%o isodd(d) ? (s, d-s)[r+1] : (d-s, s)[r+1]

%o end

%o function stripe(x, y, state)

%o x == 0 && !state && return x, y+1, !state

%o y == 0 && state && return x+1, y, !state

%o state && return x+1, y-1, state

%o return x-1, y+1, state

%o end

%o function StripeEnumeration(len)

%o x, y, state = 0, 0, false

%o for n in 0:len

%o println("$n -> ($x, $y)")

%o x, y, state = stripe(x, y, state)

%o end

%o end

%o function Pairing(x, y)

%o p = isodd(x - y) ? x : y

%o div((x + y)*(x + y + 1), 2) + p

%o end

%o StripeEnumeration(40)

%o (Python)

%o from itertools import count, islice

%o def A319571_gen(): # generator of terms

%o for n in count(0):

%o for m in range(n+1):

%o yield from (m,n-m) if n % 2 else (n-m,m)

%o A319571_list = list(islice(A319571_gen(),100)) # _Chai Wah Wu_, May 21 2022

%Y Cf. A319572 (stripe x), A319573 (stripe y).

%Y Cf. A319514 (shell enumeration), A319289 (shell x), A319290 (shell y).

%K nonn

%O 0,7

%A _Peter Luschny_, Sep 23 2018