cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A128173 Numbers in ternary reflected Gray code order.

This page as a plain text file.
%I A128173 #23 Jul 18 2020 15:43:27
%S A128173 0,1,2,5,4,3,6,7,8,17,16,15,12,13,14,11,10,9,18,19,20,23,22,21,24,25,
%T A128173 26,53,52,51,48,49,50,47,46,45,36,37,38,41,40,39,42,43,44,35,34,33,30,
%U A128173 31,32,29,28,27,54,55,56,59,58,57,60,61,62,71,70,69,66,67,68,65,64,63,72
%N A128173 Numbers in ternary reflected Gray code order.
%H A128173 Alois P. Heinz, <a href="/A128173/b128173.txt">Table of n, a(n) for n = 0..19682</a>
%H A128173 Donald E. Knuth, <a href="http://www-cs-faculty.stanford.edu/~knuth/fasc2a.ps.gz">The Art of Computer Programming, Pre-Fascicle 2A</a>, Draft of Section 7.2.1.1, subsection "Nonbinary Gray codes", page 18.  At the bottom of page 19, ternary example g hat for all m_j=3 is the present sequence.
%H A128173 Z. Sunic, <a href="https://arxiv.org/abs/math/0612080">Tree morphisms, transducers and integer sequences</a>, arXiv:math/0612080 [math.CO], 2006.
%H A128173 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%p A128173 A128173 := proc(nmax) local K,tmp,n3,n,r,c,t,a ; n3 := 3 ; n := 1 ; K := linalg[matrix](n3,1,[[0],[1],[2]]) ; while n3 < nmax do n3 := n3*3 ; n := n+1 ; tmp := K ; K := linalg[extend](K,2*n3/3,1,0) ; K := linalg[copyinto](tmp,K,1+n3/3,1) ; K := linalg[copyinto](tmp,K,1+2*n3/3,1) ; for r from 1 to n3 do K[r,n] := floor((r-1)/(n3/3)) ; od ; for r from n3/3+1 to n3/2 do for c from 1 to n do t := K[r,c] ; K[r,c] := K[n3+1-r,c] ; K[n3+1-r,c] := t ; od ; od ; od ; a := [] ; for r from 1 to n3 do a := [op(a), add( K[r,c]*3^(c-1),c=1..n) ] ; od ; a ; end: A128173(30) ; # _R. J. Mathar_, Jun 17 2007
%t A128173 a[n_] := Module[{v, r, i}, v = IntegerDigits[n, 3]; r = 0; For[i = 1, i <= Length[v], i++, If[r == 1, v[[i]] = 2 - v[[i]]]; r = Mod[r + v[[i]], 2]]; FromDigits[v, 3]];
%t A128173 a /@ Range[0, 100] (* _Jean-François Alcover_, Jul 18 2020, after _Kevin Ryde_ *)
%o A128173 (PARI) a(n) = my(v=digits(n,3),r=Mod(0,2)); for(i=1,#v, if(r,v[i]=2-v[i]); r+=v[i]); fromdigits(v,3); \\ _Kevin Ryde_, May 21 2020
%Y A128173 Cf. A003188, A105529, A105530.
%K A128173 nonn
%O A128173 0,3
%A A128173 _Ralf Stephan_, May 09 2007
%E A128173 More terms from _R. J. Mathar_, Jun 17 2007
%E A128173 Offset changed to 0 by _Alois P. Heinz_, Feb 23 2018