There are

students in a class: `STUDENTS`

boys and
`BOYS`

girls.
`GIRLS`

If the teacher picks a group of

at random, what is the probability that
everyone in the group is a `GROUP``ARE_B ? "boy" : "girl"`?

One way to solve this problem is to figure out how many different groups
there are of only `ARE_B ? "boys" : "girls"`, then divide this
by the total number of groups you could choose. Since every groups is chosen
with equal probability, this will be the probability that a group of all
`ARE_B ? "boys" : "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 `ARE_B ? "John" : "Julia"` then
`ARE_B ? "Ben" : "Beatrice"` or `ARE_B ? "Ben" : "Beatrice"` then
`ARE_B ? "John" : "Julia"`,
so order must not matter. So, the number of ways
to pick a group of

students out of `GROUP`

is
`STUDENTS`` \dfrac{`

.
[Show me why]
`STUDENTS`!}{(`STUDENTS`-`GROUP`)!`GROUP`!} =
\binom{`STUDENTS`}{`GROUP`}

Remember that the

and `STUDENTS`! \;`(`

terms come from when we
fill up the group, making `STUDENTS`-`GROUP`)! \;

choices for the first slot, then `STUDENTS`

choices for the
second, and so on. In this way, we end up making
`STUDENTS-1`

.
The `_.map(_.range(GROUP), function(l){ return (STUDENTS-l);}).join("\\cdot")`
= \dfrac{`STUDENTS`!}{(`STUDENTS`-`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.
`GROUP`

We can use the same logic to count the number of groups that only have `ARE_B ? "boys" : "girls"`.

Specifically, the number of ways to pick a group of

students out of
`GROUP`

is
`NUM_B`` \dfrac{`

.
`NUM_B`!}{(`NUM_B`-`GROUP`)!`GROUP`!} =
\binom{`NUM_B`}{`GROUP`}

So, the probability that the teacher picks a group of all `ARE_B ? "boys" : "girls"` is the number of
groups with only `ARE_B ? "boys" : "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`}

If you flip a fair coin

times, what is the probability that you will get exactly
`COINS``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

-letter word, where the first letter is "H" if the first coin toss was heads and "T"
if it was tails, and so on.
`COINS`

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

How many of these are there? If we treat all the letters as unique,
we'll find that there are

different arrangements, overcounting `COINS`!

times for every time we only switch the `NUM`!`IS_H ? "H's" : "T's"` around, and

times for every time we only switch the `COINS-NUM`!`IS_H ? "T's" : "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

HTHTT is the same as

HTHTT, and

HTHTT,

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

`5\cdot4\cdot3\cdot2\cdot1 = 5! = 120 \;`

different re-arrangements. But, this treats all the letters
as unique, when HTHTT is the same as

HTHTT, and

HTHTT,

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{`

different
outcomes where you get exactly `COINS`!}{`NUM`!`COINS-NUM`!} = `NUM_RIGHT``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^{`

total possible outcomes.
`COINS`} = `NUM_ALL`

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`}