login
Number of subsets of {1,...,n} containing {a,a+2,a+4} for some a.
3

%I #15 Jan 04 2018 02:50:57

%S 0,0,0,0,0,4,15,37,87,200,448,992,2160,4628,9823,20699,43335,90246,

%T 187068,386192,794560,1629944,3334975,6808073,13870191,28207552,

%U 57274368,116129280,235165632,475678200,961190943,1940470231,3914210127,7889613022,15891777084

%N Number of subsets of {1,...,n} containing {a,a+2,a+4} for some a.

%C Also, the number of bitstrings of length n containing 10101,11101,10111 or 11111.

%H G. C. Greubel, <a href="/A209409/b209409.txt">Table of n, a(n) for n = 0..1000</a>

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

%F A(n) = 2^n - A209410(n)

%F a(n) = 2^n - t[floor(n/2)+2]*t[floor((n+1)/2)+2] where t(n) is the n-th tribonacci number.

%F a(n) = 3*a(n-1) - 2*a(n-2) + 2*a(n-3) - 4*a(n-4) + 2*a(n-5) - 2*a(n-6) - 4*a(n-7) - a(n-8) + a(n-9) + 2*a(n-10).

%F G.f.: x^5*(4 + 3*x - 2*x^3 - x^4)/((1 - 2*x) (1 - x - x^2 - x^3) (1 + x^2 + x^4 - x^6)).

%e For n=5, subsets containing {a,a+2,a+4} occur only when a=1. There are 2^2 subsets including {1,3,5}, thus a(5) = 4.

%t LinearRecurrence[{3, -2, 2, -4, 2, -2, -4, -1, 1, 2}, {0, 0, 0, 0, 0, 4, 15, 37, 87, 200}, 40]

%o (Python)

%o #Returns the actual list of valid subsets

%o def containscode(n,bitstring=(1,0,1,0,1)):

%o .patterns=list()

%o .for start in range (1,n-len(bitstring)+2):

%o ..s=set()

%o ..for i in range(len(bitstring)):

%o ...if bitstring[i]:

%o ....s.add(start+i)

%o ..patterns.append(s)

%o .s=list()

%o .for i in range(sum(bitstring),n+1):

%o ..for temptuple in comb(range(1,n+1),i):

%o ...tempset=set(temptuple)

%o ...for sub in patterns:

%o ....if sub <= tempset:

%o .....s.append(tempset)

%o .....break

%o .return s

%o #Counts all such sets

%o def countcontainscode(n,bitstring=(1,0,1,0,1)):

%o .return len(containscode(n))

%o (Python)

%o #From recurrence

%o def a(n, adict={0:0, 1:0, 2:0, 3:0, 4:0, 5:4, 6:15, 7:37, 8:87, 9:200}):

%o .if n in adict:

%o ..return adict[n]

%o .adict[n]=3*a(n-1) - 2*a(n-2) + 2*a(n-3) - 4*a(n-4) + 2*a(n-5) - 2*a(n-6) - 4*a(n-7) - a(n-8) + a(n-9) + 2*a(n-10)

%o .return adict[n]

%o (PARI) x='x+O('x^30); concat([0,0,0,0,0], Vec(x^5*(4+3*x-2*x^3-x^4)/((1- 2*x)*(1-x-x^2-x^3)*(1+x^2+x^4-x^6)))) \\ _G. C. Greubel_, Jan 03 2018

%Y Cf. A209408, A209410.

%K nonn,easy

%O 0,6

%A _David Nacin_, Mar 08 2012