login
Three steps forward, two steps back.
9

%I #36 Feb 17 2022 00:50:29

%S 0,1,2,3,2,1,2,3,4,3,2,3,4,5,4,3,4,5,6,5,4,5,6,7,6,5,6,7,8,7,6,7,8,9,

%T 8,7,8,9,10,9,8,9,10,11,10,9,10,11,12,11,10,11,12,13,12,11,12,13,14,

%U 13,12,13,14,15,14,13,14,15,16,15,14,15,16,17,16,15,16,17,18,17,16,17,18

%N Three steps forward, two steps back.

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

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

%F a(n) = a(n-5) + 1.

%F a(n) = a(n-1) + 1 if n=1, 2 or 3 mod 5.

%F a(n) = a(n-1) - 1 if n=0 or 4 mod 5.

%F G.f.: (x*(1+x+x^2-x^3-x^4))/((x-1)^2*(1+x+x^2+x^3+x^4)). [Corrected by _Georg Fischer_, May 18 2019]

%F a(n) = n/5 + 4/5*((n mod 5) mod 4) + (6/5)*floor((n mod 5)/4). - _Rolf Pleisch_, Jul 26 2009

%F a(n) = Sum_{i=1..n} (-1)^floor((2*i-2)/5). - _Wesley Ivan Hurt_, Oct 28 2015

%p A058207:=n->add((-1)^floor((2*i-2)/5), i=1..n): seq(A058207(n), n=0..100); # _Wesley Ivan Hurt_, Oct 28 2015

%t a[n_] := Quotient[n, 5] + {0, 1, 2, 3, 2}[[Mod[n, 5] + 1]]; Table[a[n], {n, 0, 82}] (* _Jean-François Alcover_, Dec 12 2011, after _Charles R Greathouse IV_ *)

%t LinearRecurrence[{1,0,0,0,1,-1},{0,1,2,3,2,1},110] (* _Harvey P. Dale_, Feb 27 2013 *)

%o (Magma) [ n le 4 select n-1 else n eq 5 select 2 else Self(n-5)+1: n in [1..83] ]; // _Klaus Brockhaus_, Apr 14 2009

%o (Haskell)

%o a058207 n = a058207_list !! n

%o a058207_list = f [0,1,2,3,2] where f xs = xs ++ f (map (+ 1) xs)

%o -- _Reinhard Zumkeller_, Jul 28 2011

%o (PARI) a(n)=n\5+[0,1,2,3,2][n%5+1] \\ _Charles R Greathouse IV_, Jul 28 2011

%Y Cf. A008611.

%K easy,nonn,nice

%O 0,3

%A _Henry Bottomley_, Nov 29 2000

%E Second formula corrected by _Charles R Greathouse IV_, Jul 28 2011