puzzle contents
Contents
raw puzzle

In a tombola you can win one out of 5 prices. You know that 300 tickets where sold and to increase the chance to win you bought 13 of those tickets. What is the probability to win?

Solution

It's easier to think of the probability to lose. The probability that your first ticket is a blank is \(\frac{295}{300}\). Now assumed the first was a blank, the probability the second ticket is a blank as well is \(\frac{294}{299}\). When we continue this for all 13 tickts we have, we get the probability of losing in this game:

let p = 1;
for (let i = 0; i < 13; i++) {
  p*= (300 - 5 - i) / (300 - i);
}
console.log("Probability to win: ", 1 - p);

Now the question arises, what does a general formulation look like?

Let's say we have \(n\) tickets, buy \(b\) on our own and there are \(w\) chances to win. The numerator to calculate the laplace probability is \((n - w) \cdot (n - w - 1) \cdot \dots \cdot (n - w - b) = \frac{(n-w)!}{(n-w-b)!}\). Similarly for the denominator \(n! \cdot (n-1)! \cdot (n-2)! \cdot \dots\cdot \cdot (n-b)! = \frac{n!}{(n-b)!}\)

Remembering that the number of variations is

\[V(k, n) := \frac{n!}{(n - k)!}\]

Which gives the probability to lose with

\[P(\text{lose}) = \frac{V(b, n-w)}{V(b, n)}\]

Finally, to calculate the probability to win, a simple implementation may look like

function variation(k, n) {
  let p = 1
  for (k = n - k; ++k <= n; ) p*= k;
  return p;
}

function solution(n, w, b) {
   return 1 - variation(b, n - w) / variation(b, n);
}