Originally Posted by

**DivideBy0** Ok I'll have a crack at it, it might be wrong though

Let random numbers $\displaystyle x-y=n-d$. It doesn't matter how many trials there are, but as long as the difference between the number of times a success (x) is flipped and a failure (y) is flipped is the same, then we will have increased by x-y = n-d to reach n.

Then there are $\displaystyle \ _{x+y}C_x$ ways to arrange the probabilities

So

$\displaystyle Pr(Success)={{x+y} \choose x} p^x (1-p)^y$

Of course it requires to know 3 things:

1. N

2. D

3. The number of trials.

It also looks quite similar to hypergeometric distribution

thanks for posting this problem :P