# How many sequences :$a_1,a_2,…,a_8$

How many sequences $a_1,a_2,...,a_8$ from zeros and ones ,and such that :

$$a_1\cdot a_2+a_2 \cdot a_3+\cdots + a_7\cdot a_8=5$$

-
Is this homework ? what did you try ? –  Belgi Sep 19 '12 at 12:04
You can solve the problem by analyzing how many zeros there are in the sequence and in each case which are the possible cases. –  digital-Ink Sep 19 '12 at 12:17

I will use Haskell to brute-force this. Here's a GHCi session:

Prelude> let xs = [ (a1,a2,a3,a4,a5,a6,a7,a8) | a1 <- [0,1], a2 <- [0,1],
a3 <- [0,1], a4 <- [0,1],
a5 <- [0,1], a6 <- [0,1],
a7 <- [0,1], a8 <- [0,1],
a1*a2 + a2*a3 + a3*a4 + a4*a5 + a5*a6 + a6*a7 + a7*a8 == 5]
Prelude> xs
[(0,0,1,1,1,1,1,1),(0,1,1,1,1,1,1,0),(1,0,1,1,1,1,1,1),(1,1,0,1,1,1,1,1),(1,1,1,0,1,1,1,1),(1,1,1,1,0,1,1,1),(1,1,1,1,1,0,1,1),(1,1,1,1,1,1,0,0),(1,1,1,1,1,1,0,1)]
Prelude> length xs
9


So, the answer would be: there are $9$ sequences.

-
Hey, you missed a5*a6!!! These sequences listed all give 6. –  Berci Sep 19 '12 at 12:34
@BerciPecsi: You're totally right. I noticed the error and fixed it before I saw your comment. –  Rod Carvalho Sep 19 '12 at 12:37
Hint: note that this means that exactly $5$ of the pairs are of the form $1\cdot 1$