Solution (source code)

= Solution

The <sampling without replacement> makes all $\binom n2$ unordered pairs equally likely. The count of red-red pairs is $\binom32=3$, while the count of mixed pairs is $3(n-3)$. Thus their <probabilities> satisfy
$$
\frac{3(n-3)}{\binom n2}=3\frac3{\binom n2},
$$
and cancellation gives $n-3=3$. Hence $\boxed{n=6}$, with three black socks. The count of black-black pairs is also $\binom32=3$, so
$$
\boxed{\mathbb P(\text{two black socks})=\frac{\binom32}{\binom62}=\frac15.}
$$
The mixed, red-red and black-black <probabilities> are respectively $3/5,1/5,1/5$, which add to one and verify the given ratio.