## Description

Peter enjoys taking risks, and this time he has decided to take it up a notch!

Peter asks his local barman to pour him **n** shots, after which Peter then puts laxatives in **x** of them. He then turns around and lets the barman shuffle the shots. Peter approaches the shots and drinks **a** of them one at a time. Just one shot is enough to give Peter a runny tummy. What is the probability that Peter doesn't need to run to the loo?

## Task

You are given:

**n** - The total number of shots.

**x** - The number of laxative laden shots.

**a** - The number of shots that peter drinks.


return the probability that Peter won't have the trots after drinking. **n** will always be greater than **x**, and **a** will always be less than **n**.

**You must return the probability rounded to two decimal places i.e. 0.05 or 0.81**

Source: codewars | Difficulty: EASY
Tags: Ad-hoc

Mathematics

Probability

Starter code: def get_chance(n, x, a):
	

Solutions:
from functools import reduce

def get_chance(n, x, a):
	return round(reduce(lambda m, b: m * (1 - x / (n - b)), range(a), 1), 2)


def get_chance(n, x, a):
	r = 1
	z = n - x
	while a > 0:
		r *= z / n
		n -= 1
		z -= 1
		a -= 1
	return round(r, 2)


def get_chance(shots, laxatives, drinks):
	proba = 1
	for i in range(drinks):
		proba *= 1 - laxatives / shots
		shots -= 1
	return round(proba, 2)


from operator import mul
from functools import reduce

def get_chance(n, x, a):
	return round(reduce(mul, ((n - i - x) / (n - i) for i in range(a))), 2)


import numpy as np

def get_chance(n, x, a):
	ns = np.arange(n, n - a, -1)
	return np.multiply.reduce((ns - x) / ns).round(2)


def get_chance(n, x, a):
	p = 1
	for i in range(a):
		p = p * (n - x - i) / (n - i)
	return float('{:.2f}'.format(p) if p < 1 else 0.0)


from functools import reduce

def get_chance(n, x, a):
	return round(reduce(lambda x, y: x * y, ((n - x - i) / (n - i) for i in range(a))), 2)


def get_chance(n, x, a):
	prob = 1
	while a:
		prob *= (n - x) / n
		n -= 1
		a -= 1
	return round(prob, 2)


def get_chance(n, x, a):
	output = 1
	for i in range(0, a):
		if n - i == x:
			return 0
		output *= (n - x - i) / (n - i)
	return round(output, 2)


def get_chance(n, x, a):
	c = 0
	r = n - x
	p = 1
	while c < a:
		b = r / n
		p = p * b
		r = r - 1
		n = n - 1
		c = c + 1
	return round(p, 2)