login
a(n) = if n mod 2 == 0 then n*(n+1)/2, otherwise (n-1)*n/2 + 1.
12

%I #40 Jul 25 2024 17:21:18

%S 0,1,3,4,10,11,21,22,36,37,55,56,78,79,105,106,136,137,171,172,210,

%T 211,253,254,300,301,351,352,406,407,465,466,528,529,595,596,666,667,

%U 741,742,820,821,903,904,990,991,1081,1082,1176,1177,1275,1276,1378,1379,1485

%N a(n) = if n mod 2 == 0 then n*(n+1)/2, otherwise (n-1)*n/2 + 1.

%C From _Wesley Ivan Hurt_, Jun 24 2024: (Start)

%C Fill an array with the natural numbers n = 1,2,... along diagonals in alternating 'down' and 'up' directions. For n > 0, a(n) is row 1 of the boustrophedon-style array (see example).

%C In general, row k is given by (1+t^2+(n-k)*(-1)^t)/2, t = n+k-1. Here, k=1, n>0. (End)

%H Reinhard Zumkeller, <a href="/A131179/b131179.txt">Table of n, a(n) for n = 0..10000</a>

%H <a href="/index/Rec#order_05">Index entries for linear recurrences with constant coefficients</a>, signature (1,2,-2,-1,1).

%F G.f.: -x*(1+2*x-x^2+2*x^3)/((1+x)^2*(x-1)^3). - _R. J. Mathar_, Sep 05 2012

%F a(n) = ( n^2+1+(n-1)*(-1)^n )/2. - _Luce ETIENNE_, Aug 19 2014

%e [ 1] [ 2] [ 3] [ 4] [ 5] [ 6] [ 7] [ 8] [ 9] [10] [11] [12]

%e [ 1] 1 3 4 10 11 21 22 36 37 55 56 78 ...

%e [ 2] 2 5 9 12 20 23 35 38 54 57 77 ...

%e [ 3] 6 8 13 19 24 34 39 53 58 76 ...

%e [ 4] 7 14 18 25 33 40 52 59 75 ...

%e [ 5] 15 17 26 32 41 51 60 74 ...

%e [ 6] 16 27 31 42 50 61 73 ...

%e [ 7] 28 30 43 49 62 72 ...

%e [ 8] 29 44 48 63 71 ...

%e [ 9] 45 47 64 70 ...

%e [10] 46 65 69 ...

%e [11] 66 68 ...

%e [12] 67 ...

%e ...

%e - _Wesley Ivan Hurt_, Jun 24 2024

%t LinearRecurrence[{1, 2, -2, -1, 1}, {0, 1, 3, 4, 10}, 60] (* _Jean-François Alcover_, Feb 12 2016 *)

%t Table[If[EvenQ[n],(n(n+1))/2,(n(n-1))/2+1],{n,0,60}] (* _Harvey P. Dale_, Jul 25 2024 *)

%o (Haskell)

%o a131179 n = (n + 1 - m) * n' + m where (n', m) = divMod n 2

%o -- _Reinhard Zumkeller_, Oct 12 2013

%o (Magma) [(n^2+1+(n-1)*(-1)^n )/2: n in [0..60]]; // _Vincenzo Librandi_, Feb 12 2016

%o (Python)

%o def A131179(n): return n*(n+1)//2 + (1-n)*(n % 2) # _Chai Wah Wu_, May 24 2022

%Y Cf. A128918.

%Y For rows k = 1..10: this sequence (k=1) n>0, A373662 (k=2), A373663 (k=3), A374004 (k=4), A374005 (k=5), A374007 (k=6), A374008 (k=7), A374009 (k=8), A374010 (k=9), A374011 (k=10).

%K nonn,easy

%O 0,3

%A Philippe LALLOUET, Sep 16 2007