Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 13 commits
  • 6 files changed
  • 0 commit comments
  • 5 contributors
Commits on Aug 06, 2012
@xymostech xymostech Remove report logging b895cd9
@xymostech xymostech Merge pull request #27482 from xymostech/remove-logs
Remove report logging
4079c63
Commits on Aug 07, 2012
@xymostech xymostech Add exercise "Views of a function"
Summary:
Add three problem types of converting functions between differnt forms:
    graph to table
    table to graph
    equation to table

Test Plan: I tested in Chrome dev, but nothing fancy, so it should work

Reviewers: eater, mark, omar

Reviewed By: mark

Differential Revision: http://phabricator.khanacademy.org/D477
b7691c4
@beneater beneater Use "neither" instead of "none" when referring to 2 people
Reviewers: mark

Reviewed By: mark

Differential Revision: http://phabricator.khanacademy.org/D532
33c1c96
@spicyj spicyj Fix views_of_a_function compilation 2687eeb
@xymostech xymostech Stop all the dumb garbage collection
I don't see any weird side effects of this, and it returns 0 like normal
as well. I think it should be safe, but someone might want to do some
additional checking.
c5dc718
@xymostech xymostech Merge pull request #27555 from xymostech/fix-pack
Stop all the dumb garbage collection in build/pack.rb
f13e3d9
@xymostech xymostech Make build/pack.rb return 0 on success 9e4a4b9
Commits on Aug 08, 2012
@Sohl-Dickstein Sohl-Dickstein Modified the array of possible jump lengths for moving through questi…
…ons so that all of them are coprime with the number of question bins. This guarantees that users will not repeat a question until they have seen 'bins' questions. Reference Ben Alpert

Reviewers: alpert

CC: eater, jace

Differential Revision: http://phabricator.khanacademy.org/D548
1293c32
@Sohl-Dickstein Sohl-Dickstein Modified the array of possible jump lengths for moving through questi…
…ons so that all of them are coprime with the number of question bins. This guarantees that users will not repeat a question until they have seen 'bins' questions. Reference Ben Alpert

Reviewers: alpert

Reviewed By: alpert

CC: eater, jace

Differential Revision: http://phabricator.khanacademy.org/D548
eabb716
@beneater beneater Add khanscript!
Summary:
You can now create <script type="text/khanscript"> blocks in exercise questions
and hints that get executed at the right time. This can basically be used
wherever we use graphie but don't need SVG.

Reviewers: emily, alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D549
b0613b7
@Sohl-Dickstein Sohl-Dickstein Merge branch 'master' of https://github.com/Khan/khan-exercises 65c3bc4
Commits on Aug 09, 2012
@mwittels add expected value exercise
Reviewers: eater

Reviewed By: eater

CC: emily

Differential Revision: http://phabricator.khanacademy.org/D531
260074b
View
2 build/pack.rb
@@ -156,3 +156,5 @@ def uglifier_insane
f.write doc.to_html
end
end
+
+exit! 0
View
5 exercises/dependent_probability.html
@@ -86,8 +86,9 @@
<p class="question">
If the teacher chooses <code><var>CHOSEN</var></code>
students, what is the probability that
- <var>ALL ? ((CHOSEN === 2) ? "both" : "all") : "none"</var>
- of them <var>EVENT_PY</var>?
+ <var>ALL ? ((CHOSEN === 2) ? "both" : "all") :
+ ((CHOSEN === 2) ? "neither" : "none")</var>
+ of them <var>EVENT_PY</var>?
</p>
<div class="solution" data-forms="proper">
View
294 exercises/expected_value.html
@@ -0,0 +1,294 @@
+<!DOCTYPE html>
+<html data-require="math word-problems math-format">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Expected Value</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+
+ <div class="problems">
+ <div id="game" data-weight="2">
+ <div class="vars">
+ <var id="RESULT_DESC, MAKE_COUNT">randFromArray([
+ ["a 1", 1],
+ ["a 2", 1],
+ ["a 3", 1],
+ ["a 4", 1],
+ ["a 5", 1],
+ ["a 6", 1],
+ ["a 7", 1],
+ ["an 8", 1],
+ ["a 9", 1],
+ ["a 10", 1],
+ ["at least a 2", 9],
+ ["at least a 5", 6],
+ ["at least a 7", 4],
+ ["more than a 2", 8],
+ ["more than a 6", 4],
+ ["more than an 8", 2],
+ ["less than a 4", 3],
+ ["less than a 7", 6],
+ ["less than an 8", 7],
+ ["an even number", 5],
+ ["an even number", 5],
+ ["an odd number", 5],
+ ["an odd number", 5]
+ ])</var>
+ <var id="LOSE_COUNT">10 - MAKE_COUNT</var>
+ <var id="MAKE_FR">fraction(MAKE_COUNT,10,true,false)</var>
+ <var id="LOSE_FR">fraction(LOSE_COUNT,10,true,false)</var>
+ <var id="MAKE">randRange(5,10)</var>
+ <var id="LOSE">randRange(5,10)</var>
+ <var id="PROFIT">MAKE_COUNT*MAKE - LOSE_COUNT*LOSE</var>
+ <var id="ANS_F,ANS">
+ [fraction(PROFIT,10,true,false),
+ (PROFIT/10).toFixed(2)]
+ </var>
+ </div>
+
+ <p>
+ A game at the carnival offers these odds: you get to roll a
+ ten-sided die, and if you roll <var>RESULT_DESC</var>,
+ you make <code><var>MAKE</var></code> dollars. Unfortunately,
+ if you roll anything else, you lose
+ <code><var>LOSE</var></code> dollars.
+ </p>
+
+ <p class="question">
+ How much money do you expect to make (or lose)
+ playing this game?
+ </p>
+
+ <div class="solution" data-type="multiple">
+ <code>$</code>
+ <span class="sol" data-forms="decimal"><var>ANS</var></span>
+ </div>
+
+ <div class="hints">
+ <p>
+ The expected value of an event (like playing this game)
+ is average of the values of each outcome. Since some
+ outcomes are more likely than others (sometimes), we
+ weight the value of each outcome according to its
+ probability to get an accurate idea of what value
+ to expect.
+ </p>
+ <p>
+ There are two events that can happen in this game: either
+ you roll <var>RESULT_DESC</var>, or you don't. So, the
+ expected value will look like this:
+ </br></br>
+ <code>E = </code>
+ (money gained when you roll <var>RESULT_DESC</var>)
+ <code>\cdot</code>
+ (probability of rolling <var>RESULT_DESC</var>)
+ <code>+</code>
+ (money gained when you don't roll <var>RESULT_DESC</var>)
+ <code>\cdot</code>
+ (probability of not rolling <var>RESULT_DESC</var>).
+ </p>
+ <p>
+ The money you gain when you win
+ is <code>$<var>MAKE</var></code>.
+ The probability of winning is the probability
+ that you roll <var>RESULT_DESC</var>.
+ </p>
+ <p>
+ This probability is the number of winning outcomes
+ divided by the total number of
+ outcomes, <code><var>MAKE_FR</var></code>.
+ </p>
+ <p>
+ The money you gain when you lose is
+ <code>$ -<var>LOSE</var></code>
+ (since you actually lose money). The probability that
+ you lose is the probability that you don't roll
+ <var>RESULT_DESC</var>.
+ </p>
+ <p>
+ This probability must be
+ <code>1 - <var>MAKE_FR</var> = <var>LOSE_FR</var></code>.
+ </p>
+ <p>
+ So, if we take the average of the amount of money you make
+ on each outcome, weighted by how probable each outcome is,
+ we get the expected amount of money you will make:
+ <code>(<var>MAKE</var>\cdot<var>MAKE_FR</var>) +
+ (-<var>LOSE</var>\cdot<var>LOSE_FR</var>) =
+ $<var>ANS_F</var> = $<var>ANS</var>.
+ </code>
+ </p>
+ </div>
+ </div>
+ <div id="die" data-weight="1">
+ <div class="vars">
+ <var id="SIDES">randFromArray([4,6,10,12])</var>
+ <var id="SUM">
+ (function(){
+ if(SIDES &lt; 7) {
+ return _.map(_.range(SIDES), function(i){
+ return "\\dfrac{"+(i+1)+"}{"+SIDES+"}"; })
+ .join("+");
+ }
+
+ first = _.map(_.range(3), function(i){
+ return "\\dfrac{"+(i+1)+"}{"+SIDES+"}"; })
+ .join("+");
+ last = _.map(_.range(3), function(i){
+ return "\\dfrac{"+(SIDES-2+i)+"}{"+SIDES+"}"; }).join("+");
+ return [first,"\\cdots",last].join("+");
+ })()
+ </var>
+ <var id="ANS_N">
+ _.reduce(_.range(SIDES), function(n,i){ return n+i+1; }, 0)
+ </var>
+ </div>
+ <p class="question">
+ If you roll a <var>SIDES</var>-sided die, what is the expected
+ value you will roll?
+ </p>
+
+ <div class="solution" data-forms="mixed, improper, decimal">
+ <var>ANS_N/SIDES</var>
+ </div>
+
+ <div class="hints">
+ <p>
+ The expected value of an event (like rolling a die)
+ is average of the values of each outcome. To get an
+ accurate idea of what value of expect, we
+ weight the value of each outcome according to its
+ probability.
+ </p>
+ <p>
+ In this case, there are <var>SIDES</var> outcomes:
+ the first outcome is rolling a 1, the second outcome is
+ rolling a 2, and so on. The value of each of these outcomes
+ is just the number you roll.
+ </p>
+ <p>
+ So, the value of the first outcome is 1, and its
+ probability is <code>\dfrac{1}{<var>SIDES</var>}</code>.
+ </p>
+ <p>
+ The value of the second outcome is 2, the value of
+ the third outcome is 3, and so on. There are
+ <var>SIDES</var> outcomes altogether, and each of them
+ occurs with probability
+ <code>\dfrac{1}{<var>SIDES</var>}</code>.
+ </p>
+ <p>
+ So, if we average the values of each of these outcomes,
+ we get the expected value we will roll, which is
+ <code><var>SUM</var> =
+ <var>mixedFractionFromImproper(ANS_N,SIDES,true,true)</var></code>.
+ </p>
+ </div>
+ </div>
+ <div id="lottery" data-weight="2">
+ <div class="vars">
+ <var id="BUY">random() &lt; 0.4</var>
+ <var id="COST">randRange(2,4)</var>
+ <var id="ODDS">randRange(1,5)*100</var>
+ <var id="PRIZE">BUY ?
+ COST*ODDS + randRange(1,3)*100 :
+ COST*ODDS - randRange(1,3)*100
+ </var>
+ <var id="ODD_F">fraction(1,ODDS,true,true)</var>
+ <var id="ANS">BUY ?
+ "Yes, the expected value is positive." :
+ "No, the expected value is negative."
+ </var>
+ </div>
+
+ <p>
+ You decide you're only going to buy a lottery ticket if the
+ expected amount of money you will get is positive. Tickets
+ cost <code>$<var>COST</var></code>, and you get
+ <code>$<var>PRIZE</var></code> if you win. The odds of
+ winning are <code>1</code> in <code><var>ODDS</var></code>,
+ meaning that you will win with probability
+ <code><var>ODD_F</var></code>.
+ </p>
+
+ <p class="question">
+ Should you buy a ticket for this lottery?
+ </p>
+
+ <div class="solution">
+ <var>ANS</var>
+ </div>
+
+ <ul class="choices" data-category="true">
+ <li>Yes, the expected value is positive.</li>
+ <li>No, the expected value is negative.</li>
+ </ul>
+
+ <div class="hints">
+ <p>
+ The expected value of an event (like buying a lottery
+ ticket) is the average of the values of each outcome.
+ In this case, the outcome where you win is much less likely
+ than the outcome that you lose. So, to get an accurate idea
+ of how much money you expect to win or lose, we have to
+ take an average weighted by the probability of each outcome.
+ </p>
+ <p>
+ As an equation, this means the expected amount of money
+ you will win is
+ <code>E = </code> (money gained when you win)
+ <code>\cdot</code> (probability of winning) <code>+</code>
+ (money gained when you lose)
+ <code>\cdot</code> (probability of losing)
+ .
+ </p>
+ <p>
+ Let's figure out each of these terms one at a time. The
+ money you gain when you win is your winnings minus the
+ cost of the ticket, <code>$<var>PRIZE</var> -
+ $<var>COST</var></code> (you may find the math easier
+ if you <b>don't</b> simplify this).
+ </p>
+ <p>
+ From the question, we know the probability of winning is
+ <code><var>ODD_F</var></code>.
+ </p>
+ <p>
+ The money you gain when you lose is actually negative,
+ and is just the cost of the ticket,
+ <code>-$<var>COST</var></code>.
+ </p>
+ <p>
+ Finally, the probability of losing is <code>(1 -
+ <var>ODD_F</var>)</code> (you may find the math
+ easier if you <b>don't</b> simplify this).
+ </p>
+ <p>
+ Putting it all together, the expected value is
+ <code>E = ($<var>PRIZE</var> - $<var>COST</var>)
+ (<var>ODD_F</var>) + (-$<var>COST</var>)
+ (1 - <var>ODD_F</var>) = </code>
+ <code> $ \dfrac{<var>PRIZE</var>}
+ {<var>ODDS</var>} - $ \cancel{\dfrac{<var>COST</var>}
+ {<var>ODDS</var>}} - $<var>COST</var> +
+ $ \cancel{\dfrac{<var>COST</var>}{<var>ODDS</var>}} =
+ $<var>fraction(PRIZE,ODDS,true,true)</var> -
+ $<var>COST</var></code>.
+ </p>
+ <p>
+ <code>$<var>fraction(PRIZE,ODDS,true,true)</var> -
+ $<var>COST</var></code> is
+ <var>PRIZE/ODDS - COST > 0 ? "positive" : "negative"</var>.
+ </br></br>
+ So, we expect to <var>PRIZE/ODDS - COST > 0 ? "make" : "lose"</var> money by buying a lottery ticket, because
+ the expected value is <var>PRIZE/ODDS - COST > 0 ?
+ "positive" : "negative"</var>.
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
View
515 exercises/views_of_a_function.html
@@ -0,0 +1,515 @@
+<!DOCTYPE html>
+<html data-require="math graphie interactive">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Views of a function</title>
+ <script src="../khan-exercise.js"></script>
+ <script type="text/javascript">
+ chooseXValues = function(func, scale) {
+ var xs = [];
+ _.each(_.range(-9, 10), function(x) {
+ var y = func(x);
+ if (Math.abs(y) > 9) {
+ return;
+ }
+ if (Math.abs(y - Math.round(y * scale) / scale) < 0.1) {
+ xs.push(x);
+ }
+ });
+ return xs;
+ };
+ </script>
+ <style type="text/css">
+ .ttable {
+ text-align: left;
+ margin-top: 30px;
+ margin-left: 30px;
+ }
+
+ .ttable tr {
+ height: 23px;
+ }
+
+ .ttable td {
+ padding: 0px 5px;
+ text-align: right;
+ }
+
+ .ttable .labels td {
+ padding-left: 10px;
+ text-align: left;
+ border-bottom: 2px solid black;
+ }
+
+ .ttable .cross-bar td {
+ padding-top: 5px;
+ }
+
+ .ttable .second-col {
+ border-left: 2px solid black;
+ }
+
+ .ttable .data-col {
+ min-width: 40px;
+ }
+
+ #table-to-graph .ttable {
+ margin-bottom: 20px;
+ }
+ </style>
+</head>
+<body>
+<div class="exercise">
+ <div class="vars" data-ensure="EXAMPLES.length === 5">
+ <var id="A">randRangeNonZero(-3, 3)</var>
+ <var id="B">randRangeNonZero(-3, 3)</var>
+ <var id="C">randRangeNonZero(-3, 3)</var>
+ <var id="SIGNIFY">function(a) {
+ return (a === 1) ? "" : (a === -1) ? "-" : a;
+ }</var>
+ <var id="ASHOW,BSHOW,CSHOW">[SIGNIFY(A), SIGNIFY(B), SIGNIFY(C)]</var>
+ <var id="FUNC,FUNCSHOW">randFromArray([
+ [function(x) {
+ return B * x + C;
+ }, BSHOW + " x + " + C],
+ [function(x) {
+ return B / 2 * x * x + A * x + C;
+ }, ((B === 2) ? "" : (B === -2) ? "-" : (B / 2)) +
+ " x^2 + " + ASHOW + " x + " + C],
+ [function(x) {
+ return B * sin(C * x / Math.PI) + A;
+ }, BSHOW + " \\sin\\left(" + CSHOW + " x / \\pi\\right) + " + A],
+ [function(x) {
+ return B * pow(Math.E, C * x / 3) + A;
+ }, BSHOW + "e^{" +
+ ((abs(C) === 3) ? SIGNIFY(C/3) + "x" : CSHOW + " x / 3") +
+ "} + " + A]
+ ])</var>
+ <var id="EXAMPLES">(function() {
+ var xs = chooseXValues(FUNC, 1);
+ if (xs.length &gt;= 5) {
+ return sortNumbers(shuffle(xs, 5));
+ } else {
+ xs = chooseXValues(FUNC, 2);
+ return sortNumbers(shuffle(xs, 5));
+ }
+ })()</var>
+ </div>
+ <div class="problems">
+ <div id="graph-to-table">
+ <div class="vars">
+ <var id="CORRECTOFFSET">0.5</var>
+ </div>
+ <p class="question">
+ Create a table of values for the function in the graph below.
+ Use at least 5 different points. Enter the values in the table
+ as decimals.
+ </p>
+ <div class="problem">
+ <div class="graphie" id="main">
+ graphInit({
+ range: 10,
+ scale: 20,
+ tickStep: 1,
+ labelStep: 1,
+ unityLabels: false,
+ labelFormat: function(s) {
+ return "\\small{" + s + "}";
+ },
+ axisArrows: "&lt;-&gt;"
+ });
+
+ plot(FUNC, [-10, 10], { stroke: BLUE });
+ </div>
+ </div>
+ <div class="solution" data-type="custom">
+ <div class="instruction">
+ <span>Enter your data in the table below.</span>
+ <table class="ttable">
+ <tr class="labels">
+ <td><code>x</code></td>
+ <td class="second-col"><code>y</code></td>
+ </tr>
+ <tr class="cross-bar">
+ <td><input type="text" /></td>
+ <td class="second-col"><input type="text" /></td>
+ </tr>
+ <tr>
+ <td><input type="text" /></td>
+ <td class="second-col"><input type="text" /></td>
+ </tr>
+ <tr>
+ <td><input type="text" /></td>
+ <td class="second-col"><input type="text" /></td>
+ </tr>
+ <tr>
+ <td><input type="text" /></td>
+ <td class="second-col"><input type="text" /></td>
+ </tr>
+ <tr>
+ <td><input type="text" /></td>
+ <td class="second-col"><input type="text" /></td>
+ </tr>
+ <tr>
+ <td><input type="text" /></td>
+ <td class="second-col"><input type="text" /></td>
+ </tr>
+ <tr>
+ <td><input type="text" /></td>
+ <td class="second-col"><input type="text" /></td>
+ </tr>
+ </table>
+ </div>
+ <div class="guess">
+ (function(){
+ var guess = [];
+ $(".ttable tr").each(function() {
+ var input = [];
+ $(this).children().each(function() {
+ input.push($(this).children().val());
+ });
+ guess.push(input);
+ });
+ return guess;
+ })()
+ </div>
+ <div class="validator-function">
+ var attempted = 0;
+ var correct = 0;
+ var xs = [];
+
+ for (var i = 0; i &lt; 8; ++i) {
+ if ($.trim(guess[i][0]) !== "" &amp;&amp;
+ $.trim(guess[i][1]) !== "") {
+ attempted += 1;
+
+ var x = parseFloat(guess[i][0]),
+ y = parseFloat(guess[i][1]);
+
+ if (abs(FUNC(x) - y) &lt; CORRECTOFFSET) {
+ correct += 1;
+ xs.push(x);
+ }
+ }
+ }
+
+ if (attempted &lt; 5) {
+ return "You must enter 5 or more points";
+ }
+
+ xs = KhanUtil.sortNumbers(xs);
+ var different = 1;
+
+ for (var i = 0; i &lt; correct - 1; ++i) {
+ if (xs[i + 1] - xs[i] &gt;= 0.5) {
+ different += 1;
+ }
+ }
+
+ return different === attempted;
+ </div>
+ </div>
+
+ <div class="hints">
+ <p>You can look at function in many different ways, including a
+ graph and a table. Here, we have a function modeled in a
+ graph, and we want to store some information about it at a
+ couple points by modeling it as a table.</p>
+ <p>To represent it as a table, take any five points on the
+ graph, and list them in the table.</p>
+ <p>For example, we can look at the point with an
+ <code>x</code>-value of
+ <code><var>EXAMPLES[0]</var></code>.</p>
+ <div>
+ <p>The <code>y</code>-value at this point is
+ <code><var>round(2 * FUNC(EXAMPLES[0])) / 2</var></code>,
+ which we find from the graph.</p>
+ <div class="graphie" data-update="main">
+ line([EXAMPLES[0], -11], [EXAMPLES[0], 11],
+ { strokeWidth: 1, stroke: ORANGE });
+ circle([EXAMPLES[0], FUNC(EXAMPLES[0])], 0.2,
+ { stroke: ORANGE, fill: ORANGE });
+ </div>
+ </div>
+ <p>
+ To record this in our table, put
+ <code><var>EXAMPLES[0]</var></code> in the <code>x</code>
+ column, and
+ <code><var>round(2 * FUNC(EXAMPLES[0])) / 2</var></code>
+ in the <code>y</code> column.
+ </p>
+ <p>
+ We can do this with 4 other <code>x</code>-values, such as
+ <code><var>EXAMPLES[1]</var></code>,
+ <code><var>EXAMPLES[2]</var></code>,
+ <code><var>EXAMPLES[3]</var></code>,
+ and <code><var>EXAMPLES[4]</var></code>.
+ </p>
+ <div>
+ <p>We can find the <code>y</code>-values at these points
+ by finding them on the graph as well.</p>
+ <div class="graphie" data-update="main">
+ for (var i = 1; i &lt; 5; ++i) {
+ line([EXAMPLES[i], -11], [EXAMPLES[i], 11],
+ { strokeWidth: 1, stroke: ORANGE });
+ circle([EXAMPLES[i], FUNC(EXAMPLES[i])], 0.2,
+ { stroke: ORANGE, fill: ORANGE });
+ }
+ </div>
+ </div>
+ <div>
+ <p>From this, five points on the graph are:</p>
+ <div data-each="EXAMPLES as x">
+ <p><code>
+ (<var>x</var>, <var>round(FUNC(x) * 2) / 2</var>)
+ </code></p>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div id="table-to-graph">
+ <p class="question">Create a graph for the function that is modeled
+ below by plotting the points on the graph.</p>
+
+ <div class="problem">
+ <table class="ttable">
+ <tr class="labels">
+ <td class="data-col">
+ <code>x</code>
+ </td>
+ <td class="second-col data-col">
+ <code>y</code>
+ </td>
+ </tr>
+ <tr data-each="EXAMPLES as x">
+ <td class="data-col">
+ <code><var>x+"\\hphantom{.0}"</var></code>
+ </td>
+ <td class="second-col data-col">
+ <code><var>
+ roundToNearest(0.5, FUNC(x)).toFixed(1)
+ .replace(/\.0$/, "\\hphantom{.0}")
+ </var></code>
+ </td>
+ </tr>
+ </table>
+ <div class="graphie" id="main">
+ graphInit({
+ range: 10,
+ scale: 20,
+ tickStep: 1,
+ labelStep: 1,
+ unityLabels: false,
+ labelFormat: function(s) {
+ return "\\small{" + s + "}";
+ },
+ axisArrows: "&lt;-&gt;"
+ });
+
+ addMouseLayer();
+
+ graph.points = [];
+
+ var drawn = false;
+
+ graph.graphFunc = function() {
+ if (!drawn) {
+ drawn = true;
+ var func = plot(FUNC, [-10, 10],
+ { stroke: ORANGE, opacity: 0.0 });
+ func.animate({ opacity: 1.0 }, 800);
+ }
+
+ _.invoke(graph.points, "toFront");
+ };
+
+ graph.checkAnswer = function() {
+ var used = [false, false, false, false, false];
+
+ _.each(EXAMPLES, function(x) {
+ var y = roundToNearest(0.5, FUNC(x));
+ var done = false;
+ _.each(graph.points, function(pt, i) {
+ if (!done) {
+ var coord = pt.coord;
+ if (coord[0] === x &amp;&amp;
+ coord[1] === y) {
+ used[i] = true;
+ done = true;
+ }
+ }
+ });
+ });
+
+ return _.all(used, _.identity);
+ };
+
+ graph.moved = false;
+
+ graph.checkPoints = function() {
+ if (graph.checkAnswer()) {
+ graph.graphFunc();
+ }
+
+ graph.moved = true;
+
+ return true;
+ };
+
+ for (var i = 0; i &lt; 5; ++i) {
+ graph.points.push(addMovablePoint({
+ coord: [2 * i - 4, 0],
+ snapX: 0.5,
+ snapY: 0.5,
+ onMoveEnd: graph.checkPoints
+ }));
+ }
+ </div>
+ </div>
+
+ <div class="solution" data-type="custom">
+ <div class="instruction">
+ Plot the points given in the table on the graph,
+ then check your answer.
+ </div>
+ <div class="guess">
+ [
+ graph.moved,
+ graph.checkAnswer(),
+ _.pluck(graph.points, "coord")
+ ]
+ </div>
+ <div class="validator-function">
+ console.log(guess);
+ if (!guess[0]) {
+ return "";
+ } else {
+ return guess[1];
+ }
+ </div>
+ <div class="show-guess">
+ _.each(graph.points, function(pt, i) {
+ pt.setCoord(guess[2][i]);
+ });
+ </div>
+ </div>
+ <div class="hints">
+ <p>We can look at a function in many different ways, including
+ a table and a graph. Here, we have information about a
+ function at a few points, and we are trying to gain a more
+ general view of the function by plotting those points in a
+ graph.</p>
+ <p>
+ To represent it as a graph, take all the points listed in
+ the table, and plot them on the graph.</p>
+ <p>For example, let's look at the point
+ <code>
+ (<var>EXAMPLES[0]</var>,
+ <var>roundToNearest(0.5, FUNC(EXAMPLES[0]))</var>)
+ </code>.
+ </p>
+ <div>
+ <p>We need to move one of the points to this position to
+ represent plotting it on the graph.</p>
+ <div class="graphie" data-update="main">
+ var endpt = [EXAMPLES[0],
+ roundToNearest(0.5, FUNC(EXAMPLES[0]))];
+
+ line([-4, 0], endpt, { arrows: "->" });
+ graph.points[0].moveTo(endpt[0], endpt[1]);
+
+ graph.points[0].toFront();
+ </div>
+ </div>
+ <div>
+ <p>Now, plot the remaining four points by placing the
+ remaining points on the given 'X's.</p>
+ <div class="graphie" data-update="main">
+ for (var i = 1; i &lt; 5; ++i) {
+ var x = EXAMPLES[i];
+ var y = roundToNearest(0.5, FUNC(x));
+
+ line([x - 0.5, y - 0.5], [x + 0.5, y + 0.5], {
+ stroke: PINK
+ });
+ line([x + 0.5, y - 0.5], [x - 0.5, y + 0.5], {
+ stroke: PINK
+ });
+
+ _.invoke(graph.points, "toFront");
+ }
+ </div>
+ </div>
+ </div>
+ </div>
+ <div id="equation-to-table" data-type="graph-to-table">
+ <div class="vars">
+ <var id="FUNC,FUNCSHOW">randFromArray([
+ [function(x) {
+ return B * x + C;
+ }, BSHOW + " x + " + C],
+ [function(x) {
+ return B / 2 * x * x + A * x + C;
+ }, ((B === 2) ? "" : (B === -2) ? "-" : (B / 2)) +
+ " x^2 + " + ASHOW + " x + " + C]
+ ])</var>
+ <var id="EXAMPLES">(function() {
+ var xs = chooseXValues(FUNC, 1);
+ if (xs.length &gt;= 5) {
+ return sortNumbers(shuffle(xs, 5));
+ } else {
+ xs = chooseXValues(FUNC, 2);
+ return sortNumbers(shuffle(xs, 5));
+ }
+ })()</var>
+ <var id="CORRECTOFFSET">0.01</var>
+ </div>
+ <p class="question">
+ Create a table with at least five different points in it
+ created from the function. Enter the values in the table as
+ decimals.
+ </p>
+ <p class="problem"><code><var>FUNCSHOW</var></code></p>
+ <div class="hints">
+ <p>You can look at a function in many different ways,
+ including an equation and a table. We have an equation,
+ and in order to see more clearly how the function acts at
+ few points, we are going to record information about it in
+ a table.</p>
+ <p>To represent it as a table, pick some <code>x</code> values
+ to plug into the equation, and record that <code>x</code>
+ and the result of plugging it into the equation
+ in the table.</p>
+ <p>For example, try plugging in
+ <code><var>EXAMPLES[0]</var></code> to the equation.</p>
+ <p>
+ The result of <code>f(<var>EXAMPLES[0]</var>)</code> is
+ <code><var>roundToNearest(0.1, FUNC(EXAMPLES[0]))</var></code>.
+ Record this in the table by putting
+ <code><var>EXAMPLES[0]</var></code> in the <code>x</code>
+ column, and
+ <code><var>roundToNearest(0.1, FUNC(EXAMPLES[0]))</var></code>
+ in the cooresponding <code>y</code> column.
+ </p>
+ <p>
+ Now, choose four more <code>x</code> values to plug into
+ the equation. Let's try the numbers
+ <code><var>EXAMPLES[1]</var></code>,
+ <code><var>EXAMPLES[2]</var></code>,
+ <code><var>EXAMPLES[3]</var></code>,
+ and <code><var>EXAMPLES[4]</var></code>.
+ </p>
+ <div>
+ <p>By plugging into the equation, we get:</p>
+ <p data-each="EXAMPLES.slice(1) as x">
+ <code>f(<var>x</var>) =
+ <var>roundToNearest(0.1, FUNC(x))</var></code>
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+</body>
+</html>
View
13 khan-exercise.js
@@ -75,8 +75,11 @@ var Khan = (function() {
});
}
- // Prime numbers used for jumping through exercises
- var primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
+ // Numbers which are coprime to the number of bins, used for jumping through
+ // exercises. To quickly test a number in python use code like:
+ // import fractions
+ // fractions.gcd( 197, 200)
+ var primes = [197, 3, 193, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83],
/*
@@ -163,7 +166,9 @@ var Khan = (function() {
exerciseName = deslugify(exerciseId),
// Bin users into a certain number of realms so that
- // there is some level of reproducability in their questions
+ // there is some level of reproducability in their questions.
+ // If you change this, make sure all entries in the array "primes"
+ // set above are coprime to the new value.
bins = 200,
// Number of past problems to consider when avoiding duplicates
@@ -2237,7 +2242,7 @@ var Khan = (function() {
("loaded, " + (MathJax.isReady ? "" : "NOT ") + "ready, queue length: " + MathJax.Hub.queue.queue.length)),
sessionStorageInfo = (typeof sessionStorage === "undefined" || typeof sessionStorage.getItem === "undefined" ? "sessionStorage NOT enabled" : null),
warningInfo = $("#warning-bar-content").text(),
- parts = [$("#issue-body").val() || null, pathlink, historyLink, " " + JSON.stringify(guessLog), agent, sessionStorageInfo, mathjaxInfo, warningInfo, debugLogLog.join("\n")],
+ parts = [$("#issue-body").val() || null, pathlink, historyLink, " " + JSON.stringify(guessLog), agent, sessionStorageInfo, mathjaxInfo, warningInfo],
body = $.grep(parts, function(e) { return e != null; }).join("\n\n");
var mathjaxLoadFailures = $.map(MathJax.Ajax.loading, function(info, script) {
View
9 utils/khanscript.js
@@ -0,0 +1,9 @@
+(function() {
+ $.fn.khanscript = function(problem) {
+ return this.find("script[type='text/khanscript']").each(function() {
+ var code = $(this).text();
+ code = "(function() {" + code + "})()";
+ $.tmpl.getVAR(code);
+ }).end();
+ };
+})();

No commit comments for this range

Something went wrong with that request. Please try again.