If we didn't have to worry about the first and last matching, this would be fairly straight forward:
There would be 3 ways to pick the first pair and 2 ways to pick each successive pair so 3*29
But now we have to account for the case where the first and the last match. In other words we need to subtract those cases out.
Let's look at the case where the first 9 do not match but the first and the last do match. So there are 3 * 28 * 1 ways to do the first nine and only one way to choose the last, that is, it must match the first. We have to subtract this out: 3*29 - 3*28
But we have subtracted too much out now because I have subtracted out the case where the first and the ninth match so I have to add that back in 3 * 27 * 1 for the first 8 then one way for the ninth.
Now we have: 3*29 - 3*28 + 3*27
This proceeds and what we have is an alternating series looking like this: 3*∑(-1)i-1 * 2n-i for i from 1 to n-1.
Plugging 10 in for n we get 3 * [512 - 256 + 128 - 64 + 32 - 16 + 8 - 4 + 2] = 1026
It is advisable to spend some time thinking about this. Try the case when n = 4, then n = 5. Actually write out all the possibilities. Look for patterns. This is not easy stuff, and an online lesson might be advisable. [512, -256, 128, -64, 32, -16, 8, -4, 2][[512, -256, 128, -64, 32, -16, 8, -4, 2]512, -256, 128, -64, 32, -16, 8, -4, 2]

Patrick F.
05/16/23
Yehuda S.
Thanks so much. I knew to start with 3* 2^9 but did not know how to get rid of the matches. I do still have to study this a bit. But I appreciate the help.05/16/23