login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A287898 Number of ways to go up and down n stairs, with fewer than 4 stairs at a time, stepping on each stair at least once. 1

%I #56 Jun 03 2017 07:27:42

%S 1,3,9,27,79,233,687,2025,5969,17595,51865,152883,450655,1328401,

%T 3915743,11542481,34023905,100292659,295633833,871443275,2568763439,

%U 7571973753,22319994767,65792907193,193938514865,571674807403,1685132453689,4967284459107

%N Number of ways to go up and down n stairs, with fewer than 4 stairs at a time, stepping on each stair at least once.

%C Also the number of words using 0, 1 and 2 which have n-1 length and don't appear 0000 or 1111.

%H Colin Barker, <a href="/A287898/b287898.txt">Table of n, a(n) for n = 1..1000</a>

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

%F a(n+4) = 2*a(n+3) + 2*a(n+2) + 2*a(n+1) + a(n).

%F G.f.: x*(1 + x)*(1 + x^2) / (1 - 2*x - 2*x^2 - 2*x^3 - x^4). - _Colin Barker_, Jun 02 2017

%e n = 2

%e 0->1->2->0 (0), 0->2->1->0 (1), 0->1->2->1->0 (2). So a(2) = 3.

%e n = 3

%e 0->1->2->3->0 (00), 0->1->3->2->0 (01), 0->1->2->3->2->0 (02),

%e 0->2->3->1->0 (10), 0->3->2->1->0 (11), 0->2->3->2->1->0 (12),

%e 0->1->2->3->1->0 (20), 0->1->3->2->1->0 (21), 0->1->2->3->2->1->0 (22). So a(3) = 9.

%e ...

%e n = 5

%e 0->1->2->3->5->4->0 (0001), ... , 0->4->5->3->2->1->0 (1110),

%e 0->4->5->4->3->2->1->0 (1112), ... , 0->1->2->3->4->5->4->3->2->1->0 (2222).

%e So a(5) = 81 - 2 = 79.

%t CoefficientList[Series[(1 + x)*(1 + x^2)/(1 - 2*x - 2*x^2 - 2*x^3 - x^4), {x, 0, 30}], x] (* _Wesley Ivan Hurt_, Jun 02 2017 *)

%o (Ruby)

%o def f(ary, n)

%o return false if ary.size < n

%o a = ary[-1]

%o ary[-n..-2].all?{|i| i == a}

%o end

%o def A(k, n)

%o f_ary = [[]]

%o ary = [1]

%o (n - 1).times{

%o b_ary = []

%o f_ary.each{|i|

%o i0, i1, i2 = i + [0], i + [1], i + [2]

%o b_ary << i0 if !f(i0, k)

%o b_ary << i1 if !f(i1, k)

%o b_ary << i2

%o }

%o f_ary = b_ary

%o ary << f_ary.size

%o }

%o ary

%o end

%o p A(4, 10)

%o (PARI) Vec(x*(1 + x)*(1 + x^2) / (1 - 2*x - 2*x^2 - 2*x^3 - x^4) + O(x^30)) \\ _Colin Barker_, Jun 02 2017

%Y Cf. A001333, A233828(n-1).

%K nonn,easy

%O 1,2

%A _Seiichi Manyama_, Jun 02 2017

%E More terms from _Colin Barker_, Jun 02 2017

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 23 11:35 EDT 2024. Contains 371912 sequences. (Running on oeis4.)