How many unique ways are there to arrange the letters in the word `WORD`?

`ANSWER`

Let's try building the arrangements (or permutations) letter by letter. The word is

`WORD.length`

letters long:
`_.map(_.range(WORD.length), function(l){ return "_ "; }).join("")`

Now, for the first blank, we have

choices of letters to put in.
`WORD.length`

After we put in the first letter, let's say it's `PERM[0]`, we have

`WORD.length-1`

blanks left.
`PERM[0]+" "+_.map(_.range(WORD.length-1), function(l){ return "_ "; }).join("")`

For the second blank, we only have

choices of letters left to put in. So far, there were
`WORD.length-1`

unique choices we could have made.`WORD.length` \cdot `WORD.length-1`

We can continue in this fashion to put in a third letter, then a fourth, and so on. At each step, we have one fewer choice to
make, until we get to the last letter, and there's only one we can put in.

Using this method, the total number of arrangements is

`_.map(_.range(WORD.length).reverse(), function(l){ return (++l);}).join("\\cdot")` = `factorial(WORD.length)`.

Another way of writing this is `WORD.length`!

,
or `WORD.length`

factorial, but this isn't quite the right answer.
Using the above method, we assumed that all the letters were unique. But they're not! There are `REPLETTER`s, so we're counting every permutation multiple times. So every time we have these

`REPTIMES`

`factorial(REPTIMES)`

permutations:
`PERM_UNIQUE.join("</br>")`

`PERM`

Notice that we've overcounted our arrangements by

. This is not a coincidence!
This is exactly the number of ways to permute `REPTIMES`!

objects, which we were doing with the
non-unique `REPTIMES``REPLETTER`s. To address this overcounting, we need to divide the number of arrangements we counted
before by

.
`REPTIMES`!

When we divide the number of permutations we got by the number of times we're overcounting each permutation, we get

` \dfrac{``WORD.length`!}{`REPTIMES`!} = \dfrac{`factorial(WORD.length)`}{`factorial(REPTIMES)`} = `ANSWER`

You need to put your reindeer, `toSentence(NAMES)`, in a single-file line to pull your sleigh. However,
`PAIR[0]` and `PAIR[1]` are `FIGHTING ? "fighting" : "best friends"`, so you have to
`FIGHTING ? "keep them apart" : "put them next to each other"`, or they won't fly.

How many ways can you arrange your reindeer?

`ANSWER`

Forget about the reindeer that `FIGHTING ? "can't be" : "have to be"` together for a second, and let's try to
figure out how many ways we can arrange the reindeer if we don't have to worry about that.

We can build our line of reindeer one by one: there are

slots,
and we have `NAMES.length`

different reindeer we can put in the first slot.`NAMES.length`

Once we fill the first slot, we only have

reindeer left, so we only have
`NAMES.length-1`

choices for the second slot. So far, there are `NAMES.length-1`

unique choices we can make.
`NAMES.length` \cdot `NAMES.length-1` = `NAMES.length*(NAMES.length-1)`

We can continue in this way for the third reindeer, then the fourth, and so on, until we reach the last slot, where we only have one reindeer left and so we can only make one choice.

So, the total number of unique choices we could make to get to an arrangement of reindeer is

Another way of writing this is `_.map(_.range(NAMES.length).reverse(), function(l){ return (++l);}).join("\\cdot")` = `factorial(NAMES.length)`.

,
or `NAMES.length`!

factorial. But we haven't thought about the two reindeer who `NAMES.length``FIGHTING ? "can't be together" : "have to be together"` yet.

There are

different arrangements of reindeer altogether,
so we just need to subtract
all the arrangements where `factorial(NAMES.length)``PAIR[0]` and `PAIR[1]` are together. How many of these are there?

We can count the number of arrangements where `PAIR[0]` and `PAIR[1]` are together by treating them as one double-reindeer. Now we can use the same idea as before to come up with

different arrangements. But that's not quite right.
`_.map(_.range(NAMES.length-1).reverse(), function(l){ return (++l);}).join("\\cdot")` = `factorial(NAMES.length-1)`

Why? Because you can arrange the double-reindeer with `PAIR[0]` in front or with
`PAIR[1]` in front, and those are different arrangements! So the actual number of arrangements with `PAIR[0]`
and `PAIR[1]` together is `factorial(NAMES.length-1)` \cdot 2 =
`factorial(NAMES.length-1)*2`

So, subtracting the number of arrangements where `PAIR[0]` and `PAIR[1]` are together from the total number
of arrangements, we get

arrangements of reindeer where they will fly.
`ANSWER`

We can count the number of arrangements where `PAIR[0]` and `PAIR[1]` are together by treating them as one double-reindeer. Now we can use the same idea as before to come up with

different arrangements. But that's not quite right.
`_.map(_.range(NAMES.length-1).reverse(), function(l){ return (++l);}).join("\\cdot")` = `factorial(NAMES.length-1)`

Why? Because you can arrange the double-reindeer with `PAIR[0]` in front or with
`PAIR[1]` in front, and those are different arrangements! So the actual number of arrangements with `PAIR[0]`
and `PAIR[1]` together is `factorial(NAMES.length-1)` \cdot 2 =
`factorial(NAMES.length-1)*2`

How many numbers between 1 and 100 (inclusive) are divisible by `FAC1` or `FAC2`?

`FAC1_TIMES + FAC2_TIMES - BOTH_TIMES`

There are

numbers divisible by `FAC1_TIMES`

between `FAC1``1`

and `100`

, and

numbers divisible by
`FAC2_TIMES`

between `FAC2``1`

and `100`

.
[Show me why]

One way to see this is to take

` \dfrac{100}{``FAC1`} = `FAC1_TIMES`

One way to see this is to take

` \dfrac{100}{``FAC1`}

, which is between `
FAC1_TIMES`

and `FAC1_TIMES+1`

. So, starting at `0`

and adding `FAC1`

at each step, you have to take between `FAC1_TIMES`

and `FAC1_TIMES+1`

steps to get
to `100`

. Since if you take a fraction of a step you won't get to a number divisible by `FAC1`

,
you'll hit `FAC1_TIMES`

numbers divisible by `FAC1`

before you get to above `100`

.
So, there are `FAC1_TIMES`

numbers between `1`

and `100`

divisible by `FAC1`

.
Using similar logic for the second factor, we see that

` \dfrac{100}{``FAC2`} = `FAC2_TIMES`

Using similar logic for the second factor, take

` \dfrac{100}{``FAC2`}

, which is between `
FAC2_TIMES`

and `FAC2_TIMES+1`

. So, starting at `0`

and adding `FAC2`

at each step, you have to take between `FAC2_TIMES`

and `FAC2_TIMES+1`

steps to get
to `100`

. Since if you take a fraction of a step you won't get to a number divisible by `FAC2`

,
you'll hit `FAC2_TIMES`

numbers divisible by `FAC2`

before you get to above `100`

.
So, there are `FAC2_TIMES`

numbers between `1`

and `100`

divisible by `FAC2`

.
So, you might think there are

numbers divisible by one or the other, but this is overcounting something.
`FAC1_TIMES` + `FAC2_TIMES` = `FAC1_TIMES+FAC2_TIMES`

We're counting every number which is divisible by both

and `FAC1`

twice.
So, for example, `FAC2`

is counted once as a number divisible by `FAC1*FAC2`

, and then again as a number divisible by `FAC1`

.
`FAC2`

So, we need to count how many numbers are divisible by both

and `FAC1`

and subtract this from what we had before.
`FAC2`

Being divisible by both

and `FAC1`

is the same thing as being divisible by
`FAC2`

, so there `FAC1*FAC2``plural("is",BOTH_TIMES)` `BOTH_TIMES``plural("number",BOTH_TIMES)` between 1 and 100 divisible by both.

Subtracting, there are

numbers divisible by `FAC1_TIMES + FAC2_TIMES` - `BOTH_TIMES` = `FAC1_TIMES + FAC2_TIMES - BOTH_TIMES`

or `FAC1`

.
`FAC2`