Permalink
Browse files

add exercise on basic permutations

Reviewers: eater, emily

Reviewed By: eater

Differential Revision: http://phabricator.khanacademy.org/D447
  • Loading branch information...
1 parent a8d7eb1 commit 01fd1435c0d0ad31771cab48552617608db42eb5 @mwittels mwittels committed Jul 24, 2012
Showing with 84 additions and 0 deletions.
  1. +84 −0 exercises/permutations_1.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html data-require="math math-format word-problems">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Permutations 1</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+ <div class="problems">
+ <div id="letters" data-weight="0.6" data-ensure="WORD != PERM">
+ <div class="vars">
+ <var id="INDEX">randRange(0,11)</var>
+ <var id="WORD">["CLAW", "OPAL", "APE", "RULES", "ANGER", "SLIME", "FEAT", "FANCY", "SONG", "DEN", "TIGER", "IRON"][INDEX]</var>
+ <var id="PERM">shuffle(WORD).join("")</var>
+ <var id="ANSWER">factorial(WORD.length)</var>
+ </div>
+ <p class="question">How many unique ways are there to arrange the letters in the word <var>WORD</var>?</p>
+ <p class="solution" data-forms="integer"><var>ANSWER</var></p>
+ <div class="hints">
+ <div>
+ Let's try building the re-arrangements (or permutations) letter by letter. The word is <var>WORD.length</var>
+ letters long:
+ <p><var>_.map(_.range(WORD.length), function(l){ return "_ "; }).join("")</var></p>
+ <p>Now, for the first blank, we have <var>WORD.length</var> choices of letters to put in.
+ </div>
+ <div>
+ After we put in the first letter, let's say it's <var>PERM[0]</var>, we have <var>WORD.length-1</var> blanks left.
+ <p><var>PERM[0]+" "+_.map(_.range(WORD.length-1), function(l){ return "_ "; }).join("")</var></p>
+ <p>For the second blank, we only have <var>WORD.length-1</var> choices of letters left to put in. So far, there were
+ <code><var>WORD.length</var> \cdot <var>WORD.length-1</var></code> unique choices we could have made.</p>
+ </div>
+ <div>
+ 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 unique choice to
+ make, until we get to the last letter, and there's only one we can put in.
+ </br></br>
+ </div>
+ <div>
+ So, the total number of unique re-arrangements must be <code><var>_.map(_.range(WORD.length).reverse(), function(l){ return (++l);}).join("\\cdot")</var>.</code> Another way of writing this is <code><var>WORD.length</var>!</code>,
+ or <var>WORD.length</var> factorial, which is <var>ANSWER</var>.
+ </div>
+ </div>
+ </div>
+
+ <div id="reindeer" data-weight="0.4">
+ <div class="vars">
+ <var id="NUM_NAMES">randRange(4,5)</var>
+ <var id="NAMES">_.map(randRangeUnique(0,8,NUM_NAMES), function(n){
+ return ["Bloopin", "Gloopin", "Prancer", "Lancer", "Quentin", "Balthazar", "Ezekiel", "Jebediah", "Rudy"][n];
+ })
+ </var>
+ <var id="SLOTS">randRange(3, NAMES.length-1)</var>
+ <var id="ANSWER">factorial(NAMES.length)/factorial(NAMES.length-SLOTS)</var>
+ </div>
+ <p>
+ You have <var>NAMES.length</var> reindeer, <var>toSentence(NAMES)</var>, and you want to have <var>SLOTS</var> fly your sleigh.
+ You always have your reindeer fly in a single-file line.
+ </p>
+
+ <p class="question">How many different ways can you arrange your reindeer?</p>
+ <p class="solution" data-forms="integer"><var>ANSWER</var></p>
+
+ <div class="hints">
+ <div>
+ <p>We can build our line of reindeer one by one: there are <var>SLOTS</var> slots, and we have <var>NAMES.length</var>
+ different reindeer we can put in the first slot.</p>
+ </div>
+ <p>
+ Once we fill the first slot, we only have <var>NAMES.length-1</var> reindeer left, so we only have <var>NAMES.length-1</var>
+ choices for the second slot. So far, there are <code><var>NAMES.length</var> \cdot <var>NAMES.length-1</var> = <var>NAMES.length*(NAMES.length-1)</var></code> unique choices we can make.
+ </p>
+ <p>
+ We can continue in this way for the third reindeer, and so on, until we reach the last slot, where we will
+ have <var>NAMES.length - SLOTS + 1</var> choices for the last reindeer.
+ </p>
+ <p>
+ So, the total number of unique choices we could make to get to an arrangement of reindeer is <code><var>_.map(_.range(SLOTS), function(l){ return (NAMES.length - l);}).join("\\cdot")</var>.</code> Another way of writing this is <code> \dfrac{<var>NAMES.length</var>!}{(<var>NAMES.length</var>-<var>SLOTS</var>)!} = <var>ANSWER</var></code>
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>

0 comments on commit 01fd143

Please sign in to comment.