a. Pencils of the same color are identical.
Number the positions from left to right. Let's start by counting the arrangements with a blue pencil in position 1. There are four places to put the other blue pencil; then the number of arrangements of the other pencils depends on the position of the blue pencils.
Case I. B-B--- 2 arrangements: we can put a green or a yellow pencil in position 5, then the rest is forced.
Case II. B--B-- 4 arrangements: a green and yellow pencil (in either order) in positions 2 & 3, and the same for positions 5 & 6.
Case III. B---B- 2 arrangements: this is similar to Case I.
Case IV. B----B: 2 arrangements: we put a green and a yellow pencil in the two middle positions, and then the rest is forced.
So there are $2+4+2+2=10$ arrangements with a blue pencil in at the left end. By symmetry (because there are the same number of pencils of each color), there are also $10$ arrangements with a green pencil and $10$ arrangements with a yellow pencil at the left end, for a total of $10+10+10=30$ arrangements.
b. All pencils are distinguishable.
Each of the $30$ arrangements from a gives rise to $2\cdot2\cdot2=8$ arrangements by interchanging the two blue pencils, the two green pencils, and the two yellow pencils; so the number of arrangements is now $30\cdot8=240$.
Alternative solution to part a:
Let $A$ be the set of all possible arrangements of the six pencils, assuming that pencils of the same color are indistinguishable; in other words, $A$ is the set of all $6$-letter words containing $2$ Bs, $2$ Rs, and $2$ Y's. The cardinality of $A$ is given by a trinomial coefficient:
$$|A|=\binom6{2,2,2}=\frac{6!}{2!2!2!}=90.$$
We want to find $|A\setminus(B\cup R\cup Y)|$ where $B$ is the set of all arrangements with the two blue pencils adjacent, $R$ the set of all arrangements with the two red pencils adjacent, and $Y$ the set of all arrangements with the two yellow pencils adjacent. The in-and-out principle, also known as the inclusion-exclusion principle, tells us that
$$|A\setminus(B\cup R\cup Y)|=|A|-|B|-|R|-|Y|+|B\cap R|+|B\cap Y|+|R\cap Y|-|B\cap R\cap Y|.$$
By symmetry (since we have two pencils of each color), we have $|B|=|R|=|Y|$ and $|B\cap R|=|B\cap Y|=|R\cap Y|$, so we can write the in-and-out formula more simply:
$$|A\setminus(B\cup R\cup Y)|=|A|-3|B|+3|B\cap R|-3|B\cap R\cap Y|.$$
Now, if we glue the two blue pencils together and regard them as a unit, we can figure $|B|$ the same way we figured $|A|$, namely,
$$|B|=\binom5{1,2,2}=\frac{5!}{1!2!2!}=30.$$
Likewise,
$$|B\cap R|=\binom4{1,1,2}=\frac{4!}{1!1!2!}=12,$$
and
$$|B\cap R\cap Y|=\binom3{1,1,1}=\frac{3!}{1!1!1!}=3!=6,$$
and so finally
$$|A\setminus(B\cup R\cup Y)|=\binom6{2,2,2}-3\binom5{1,2,2}+3\binom4{1,1,2}+\binom3{1,1,1}=90-90+36-6=30.$$