A158289 Period 18 zigzag sequence: repeat [0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1].
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5
Offset: 0
Links
- Arkadiusz Wesolowski, Table of n, a(n) for n = 0..10000
- Index entries for linear recurrences with constant coefficients, signature (1,0,0,0,0,0,0,0,-1,1).
Crossrefs
Programs
-
Magma
[ s lt 9 select r else 9-r where r is n mod 9 where s is n mod 18: n in [0..104] ]; // Klaus Brockhaus, Sep 07 2009
-
Magma
S:=[]; a:=0; for n in [0..104] do Append(~S, a); if n mod 18 eq 0 then d:=1; else if n mod 9 eq 0 then d:=-1; end if; end if; a+:=d; end for; S; // Klaus Brockhaus, Sep 07 2009
-
Magma
&cat[[0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1]: n in [0..5]]; // Vincenzo Librandi, Jul 26 2015
-
Mathematica
a[n_] := If[m = Mod[n, 18]; m <= 9, m, 18-m]; Table[a[n], {n, 0, 85}] (* Jean-François Alcover, Jul 19 2013 *) PadRight[{}, 100, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1}] (* Vincenzo Librandi, Jul 26 2015 *)
-
PARI
a(n)=abs(n-round(n/18)*18) \\ M. F. Hasler, Jul 27 2015
Formula
a(18*k+j) = a(18*(k+1)-j) = j for k >= 0, j = 0..9.
G.f.: x*(1+x+x^2)*(1+x^3+x^6)/((1-x)*(1+x)*(1-x+x^2)*(1-x^3+x^6)). - Klaus Brockhaus, Sep 07 2009
a(n) = Sum_{i=0..n-1} (-1)^floor(i/9). - Wesley Ivan Hurt, Jul 25 2015
a(n) = abs(n - 18*round(n/18)). - Wesley Ivan Hurt, Dec 10 2016
a(n) = a(n-18) for n >= 18. - Wesley Ivan Hurt, Sep 07 2022
Extensions
Edited and extended by Klaus Brockhaus, Sep 07 2009
Comments