An unfair coin has a probability p of showing heads of between 0 and 1 (0, 1) is tossed n times. What's the probability that total count of heads is even? divisible by 3?
If it is a fair coin, then for a) even, it is probability of $$ \left(\frac{\binom{n}{2}+\binom{n}{4}+...+\binom{n}{2*int(n/2)}}{2^n}\right)$$
but how does p ∈ (0, 1) change this problem? thanks
The probability of heads even is: \begin{align} \sum_{i=0}^{\lfloor n/2\rfloor} \binom{n}{2i}p^{2i}(1-p)^{n-2i} &= \binom{n}{0} (1-p)^n+\binom{n}{2}p^2(1-p)^{n-2} + ... + \binom{n}{2\lfloor n/2 \rfloor} p^{2\lfloor n/2 \rfloor}(1-p)^{n - 2\lfloor n/2 \rfloor} \end{align}
The denominator of $2^n$ is only valid when the coin is fair since $p^k(1-p)^{n-k} = \left(\frac{1}{2}\right)^k\left(\frac{1}{2}\right)^{n-k} = \left(\frac{1}{2}\right)^n$.
You can find the explicit value of this sum as follows: $$1^n = (p+(1-p))^n = \sum_{i=0}^{n} \binom{n}{i}p^{i}(1-p)^{n-i}$$ $$((1-p)-p)^n = \sum_{i=0}^{n} (-1)^i \binom{n}{i}p^{i}(1-p)^{n-i}$$ If we add these two sums together the odd terms will cancel, so we get: $$1+(1-2p)^n = 2\sum_{i=0}^{\lfloor n/2\rfloor} \binom{n}{2i}p^{2i}(1-p)^{n-2i}$$ Hence, the probability of heads even is: $$\sum_{i=0}^{\lfloor n/2\rfloor} \binom{n}{2i}p^{2i}(1-p)^{n-2i} = \frac{1}{2}(1+(1-2p)^n)$$
The probability that the total number of heads is divisible by three is: $$\sum_{i=0}^{\lfloor n/3\rfloor}\binom{n}{3i}p^{3i}(1-p)^{n-3i} = \binom{n}{0}(1-p)^n+\binom{n}{3}p^3(1-p)^{n-3}+...+\binom{n}{3\lfloor n/3 \rfloor}p^{3\lfloor n/3 \rfloor}(1-p)^{n-{3\lfloor n/3 \rfloor}}$$ It is slightly trickier to get the (quite ugly) closed form for this one.