How many unique ways are there to arrange the letters in the word WORD?
ANSWER
Let's try building the re-arrangements (or permutations) letter by letter.
The word is LENGTH
letters long:
BLANKS
For the first blank, we have LENGTH
choices of letters.
After we put in the first letter, let's say it's \text{PERM[0]}
,
we have LENGTH - 1
blanks left.
\text{PERM[0]}
BLANKS.slice(2)
For the second blank, we only have LENGTH - 1
choices of letters left.
So far, there are LENGTH \cdot LENGTH - 1
unique choices we can make.
We can continue in this fashion to put in a third letter, and so on. At each step, we have one fewer unique choice to make, until we get to the last letter, and there's only one we can put in.
So, the total number of unique re-arrangements must be
_.map(_.range(LENGTH), function(i){ return LENGTH - i;}).join("\\cdot")
.
Another way of writing this is LENGTH!
,
or LENGTH
factorial, which is ANSWER
.
You have NUM_NAMES
reindeer, toSentence(NAMES),
and you want to have SLOTS
fly your sleigh.
You always have your reindeer fly in a single-file line.
How many different ways can you arrange your reindeer?
ANSWER
We can build our line of reindeer one by one: there are SLOTS
slots,
and we have NUM_NAMES
different reindeer we can put in the first slot.
Once we fill the first slot, we only have NUM_NAMES - 1
reindeer left,
so we only have NUM_NAMES - 1
choices for the second slot.
So far, there are NUM_NAMES \cdot NUM_NAMES - 1 = NUM_NAMES * (NUM_NAMES - 1)
unique choices we can make.
We can continue in this way for the third reindeer, where we will have NUM_NAMES - SLOTS + 1
choices.
We can continue in this way for the third reindeer, and so on, until we reach the last slot, where we will
have NUM_NAMES - SLOTS + 1
choices for the last reindeer.
So, the total number of unique choices we could make to get to an arrangement of reindeer is
_.map(_.range(SLOTS), function(l){ return (NUM_NAMES - l);}).join("\\cdot")
.
Another way of writing this is
\dfrac{NUM_NAMES!}{(NUM_NAMES-SLOTS)!} = ANSWER