combinatorics problem with ternary strings

58 Views Asked by At

A Teranary string of length 8, where each position could be 0, 1, 2. How many strings have exactly four positions equal to one such that at least one of the first or last position is equal. (link to actual question if I didn't state the question clearly: https://i.stack.imgur.com/ZLMWb.jpg)

//.

I wanted to say at any given time the first or last position would have to be 1 so $(1\cdot 1\cdot 1 \cdot 1 \cdot 3^4) + (3^4\cdot 1\cdot 1 \cdot 1\cdot 1) + (1\cdot 1\cdot 3^4 \cdot 1 \cdot 1)$. Would this be sufficient for solving the problem? First would be if the first four digits were 1, second is if the last three digits are one and third is if 1 is at both the beginning and end.

1

There are 1 best solutions below

0
On

You can either have the first and last equal to $1$, in which case you need two of the other six equal to $1$, or you can have the first and last equal to $0$ or $2$ and have four of the other six be $1$.