Solution (source code)

= Solution

Interpret random choice of coin as equal prior probabilities, and the tosses as <independent> conditional on the chosen coin. Let $H_2$ denote two heads. The conditional probabilities are $P(H_2\mid A)=1/16$ and $P(H_2\mid B)=9/16$. For <posterior coin selection from repeated tosses>, <Bayes' theorem> gives
$$
\boxed{P(B\mid H_2)=\frac{(1/2)(9/16)}{(1/2)(1/16)+(1/2)(9/16)}=\frac9{10}.}
$$
The tosses need not be unconditionally <independent>, because the same hidden coin is used twice. If the coin-choice prior were instead $P(B)=\pi$, the answer would be $9\pi/(1+8\pi)$; equal choice gives the stated $9/10$.

For <nondecreasing uniform samples> in the lottery, all $n^r$ ordered samples have equal probability by the <discrete uniform distribution> and <independence>. A nondecreasing sample is uniquely specified by its multiplicities $k_1,\ldots,k_n\geq0$, with $k_1+\cdots+k_n=r$. The <stars and bars> argument places $n-1$ separators among $r$ identical markers, giving $\binom{r+n-1}{n-1}$ multiplicity vectors. There is exactly one nondecreasing ordered sample for each such vector, so \b[the probability is]
$$
\boxed{\frac{\binom{r+n-1}{n-1}}{n^r}=\frac{\binom{r+n-1}{r}}{n^r}.}
$$
This counts samples with ties correctly; multiplying a single strictly increasing count by $r!$ would not handle the repeated values.