randRange(7,10) randRange(3,6) randRange(2,STUDENTS-2) STUDENTS-BOYS random() < 0.5 ARE_B ? BOYS : GIRLS (factorial(NUM_B)*factorial(STUDENTS-GROUP))/(factorial(STUDENTS)*factorial(NUM_B-GROUP)) getGCD(factorial(NUM_B)*factorial(STUDENTS-GROUP),factorial(STUDENTS)*factorial(NUM_B-GROUP)) factorial(NUM_B)*factorial(STUDENTS-GROUP)/GCD factorial(STUDENTS)*factorial(NUM_B-GROUP)/GCD

There are `STUDENTS` students in a class: `BOYS` boys and `GIRLS` girls.

If the teacher picks a group of `GROUP` at random, what is the probability that everyone in the group is a boy? If the teacher picks a group of `GROUP` at random, what is the probability that everyone in the group is a girl?

ANSWER

One way to solve this problem is to figure out how many different groups there are of only boys, then divide this by the total number of groups you could choose. Since every group is chosen with equal probability, this will be the probability that a group of all boys is chosen.

One way to solve this problem is to figure out how many different groups there are of only girls, then divide this by the total number of groups you could choose. Since every group is chosen with equal probability, this will be the probability that a group of all girls is chosen.

We know two ways to count the number of groups we can choose: we use permutations if order matters, and combinations if it doesn't. Does the order the students are picked matter in this case?

It doesn't matter if we pick John then Ben or Ben then John, so order must not matter. So, the number of ways to pick a group of `GROUP` students out of `STUDENTS` is `\dfrac{STUDENTS!}{(STUDENTS-GROUP)!GROUP!} = \binom{STUDENTS}{GROUP}`. [Show me why]

It doesn't matter if we pick Julia then Beatrice or Beatrice then Julia, so order must not matter. So, the number of ways to pick a group of `GROUP` students out of `STUDENTS` is `\dfrac{STUDENTS!}{(STUDENTS-GROUP)!GROUP!} = \binom{STUDENTS}{GROUP}`. [Show me why]

Remember that the `STUDENTS! \;` and `(STUDENTS-GROUP)! \;` terms come from when we fill up the group, making `STUDENTS` choices for the first slot, then `STUDENTS-1` choices for the second, and so on. In this way, we end up making `_.map(_.range(GROUP), function(l){ return (STUDENTS-l);}).join("\\cdot") = \dfrac{STUDENTS!}{(STUDENTS-GROUP)!} \;`. The `GROUP! \;` term comes from the number of times we've counted a group as different because we chose the students in a different order. There are `GROUP! \;` ways to order a group of `GROUP`, so for every group, we've overcounted exactly that many times.

We can use the same logic to count the number of groups that only have boys.

We can use the same logic to count the number of groups that only have girls.

Specifically, the number of ways to pick a group of `GROUP` students out of `NUM_B` is `\dfrac{NUM_B!}{(NUM_B-GROUP)!GROUP!} = \binom{NUM_B}{GROUP}`.

So, the probability that the teacher picks a group of all boys is the number of groups with only boys divided by the number of total groups the teacher could pick.

So, the probability that the teacher picks a group of all girls is the number of groups with only girls divided by the number of total groups the teacher could pick.

This is `\displaystyle \frac{\frac{NUM_B!}{(NUM_B-GROUP)!\cancel{GROUP!}}} {\frac{STUDENTS!}{(STUDENTS-GROUP)!\cancel{GROUP!}}} = \frac{\frac{NUM_B!}{NUM_B-GROUP!}}{\frac{STUDENTS!}{STUDENTS-GROUP!}}`

We can re-arrange the terms to make simplification easier `\left(\dfrac{NUM_B!}{NUM_B-GROUP!}\right) \left(\dfrac{STUDENTS-GROUP!}{STUDENTS!}\right) = \left(\dfrac{NUM_B!}{STUDENTS!}\right) \left(\dfrac{STUDENTS-GROUP!}{NUM_B-GROUP!}\right)`

Simplifying, we get `\left(\dfrac{\cancel{NUM_B!}}{_.map(_.range(STUDENTS-NUM_B), function(l){ return (STUDENTS-l); }).join("\\cdot") \cdot \cancel{NUM_B!}}\right) \left(\dfrac{_.map(_.range(STUDENTS-NUM_B), function(l){ return (STUDENTS-GROUP-l); }).join("\\cdot") \cdot \cancel{(NUM_B-GROUP)!}}{\cancel{NUM_B-GROUP!}}\right) = \left(\dfrac{1}{factorial(STUDENTS)/factorial(NUM_B)}\right) \left(factorial(STUDENTS-GROUP)/factorial(NUM_B-GROUP)\right) = \dfrac{PRETTY_NUM}{PRETTY_DEM}`

randRange(4,7) randRange(2,COINS-2) random < 0.5 IS_H ? $._("heads") : $._("tails") factorial(COINS)/(factorial(NUM)*factorial(COINS-NUM)) Math.pow(2,COINS) getGCD(NUM_RIGHT,NUM_ALL) NUM_RIGHT/GCD NUM_ALL/GCD

If you flip a fair coin `COINS` times, what is the probability that you will get exactly `NUM` NAME?

PRETTY_NUMER/PRETTY_DENOM

One way to solve this problem is to figure out how many ways you can get exactly `NUM` NAME, then divide this by the total number of outcomes you could have gotten. Since every outcome has equal probability, this will be the probability that you will get exactly `NUM` NAME.

How many outcomes are there where you get exactly `NUM` NAME? Try thinking of each outcome as a `COINS`-letter word, where the first letter is "H" if the first coin toss was heads and "T" if it was tails, and so on.

So, the number of outcomes with exactly `NUM` NAME is the same as the number of these words which have `NUM` H's and `COINS-NUM` T's.

So, the number of outcomes with exactly `NUM` NAME is the same as the number of these words which have `NUM` T's and `COINS-NUM` H's.

How many of these are there? If we treat all the letters as unique, we'll find that there are `COINS!` different arrangements, overcounting `NUM!` times for every time we only switch the H's around, and `COINS-NUM!` times for every time we only switch the T's around. [Show me why]

How many of these are there? If we treat all the letters as unique, we'll find that there are `COINS!` different arrangements, overcounting `NUM!` times for every time we only switch the T's around, and `COINS-NUM!` times for every time we only switch the H's around. [Show me why]

Let's say we toss a coin 5 times, and get tails three times. How many different re-arrangements are there of the letters "HHTTT"? Well, we have five choices for the first slot, four for the second slot, and so on, resulting in `5\cdot4\cdot3\cdot2\cdot1 = 5! = 120 \;` different re-arrangements. But, this treats all the letters as unique, when
HTHT T is the same as
HTHT T, and
HTHT T,
and so on. So really, we need to replace all these different re-arrangements where we only move the tails around with one re-arrangement, HTHTT. There are `3!` of these multi- colored arrangements for every normal one, so that means dividing our first guess of `5!` by `3!`. By the exact same logic, we need to divide by `2!` to avoid overcounting every permutation where we just move the heads around. So, the number of re-arrangements is `\dfrac{5!}{3!2!} = \binom{5}{3}`.

So, there are `\dfrac{COINS!}{NUM!COINS-NUM!} = NUM_RIGHT` different outcomes where you get exactly `NUM` NAME. [How many total outcomes are there?]

Well, if you only flip one coin, there are two outcomes, if you flip two there are four outcomes, if you flip three there are eight. Each time you flip another coin, you double the number of possible outcomes.

Altogether, there are `2^{COINS} = NUM_ALL` total possible outcomes.

So, the probability that you will get exactly NUM NAME is `\dfrac{NUM_RIGHT}{NUM_ALL} = \dfrac{PRETTY_NUMER}{PRETTY_DENOM}`.

So, the probability that you will get exactly NUM NAME is `\dfrac{NUM_RIGHT}{NUM_ALL}`.