Need help understanding formula for probability that something good happens before something bad happens. My book says this.
Consider a sequence of independent trials, each of which can
be classified as good, bad, or neutral, which happen (on any given trial) with
probabilities $p, q,$ and $1 − p − q$, respectively. (We do not necessarily have
$q = 1 − p$ here, although that case is allowed.) Then the probability that
something good happens before something bad happens is $p/(p + q)$.
My question is, how did they derive this formula $p/(p+q)$ for probability that something good happens before something bad happens?
can someone show me a derivation/explain to me this?
 A: Informally, you can ignore the neutral events, because if one happens you are back where you started.  You can then scale up the probabilities $p$ and $q$ so they sum to $1$, which gets the probability of something good being $\frac p{p+q}$ and the probability of something bad being $\frac q{p+q}$.  Note these sum to $1$ and have the proper ratio, which should convince you.
More formally, the chance of good before bad is a string of neutrals followed by a good and the chance of bad before good is a string of neutrals followed by a bad.  Again, the ratio has to be $\frac pq$ and the sum has to be $1$ because the chance of an infinite string of neutrals is $0$.  If you want, you can sum the geometric series and get the same result for more work.
A: In the repeated trials, the only try that matters is the first one that isn't neutral. For that one, it's good before bad if and only if that one is good. The probability is then as advertised: the probability of good divided by the probability that the try matters.
A: Let $B$ denote the first trial where something bad happens, and let $X$ denote the number of times something good happens within the first $B-1$ trials. Then $B\sim \text{Geometric}(q)$ and $X|B\sim \text{Binomial}\Big(B-1,\frac{p}{1-q}\Big)$ and you're looking to compute $$P(X\geq 1)=1-P(X=0)$$ From the total law of probability, $$P(X=0)=\sum_{b=1}^{\infty}P(X=0|B=b)P(B=b)=\sum_{b=1}^{\infty}\Big(\frac{1-p-q}{1-q}\Big)^{b-1}(1-q)^{b-1}q$$ The RHS evaluates to $\frac{q}{p+q}$ and so $$P(X\geq 1)=1-\frac{q}{p+q}=\frac{p}{p+q}$$
