Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

88 lines (83 sloc) 4.164 kb
<!DOCTYPE html>
<html data-require="math expressions">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Expressions with unknown variables 2</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="NUM_EXPRESSIONS">randRange( 1, 2 )</var>
<var id="NUM_TERMS">randRange( 2, 3, NUM_EXPRESSIONS )</var>
<var id="COEFFICIENTS">[ randRange( 1, 9, 3 ), randRange( 1, 9, 3 ) ]</var>
<var id="GROUPS">
(function() {
var variables = [ [ "a", "b", "c" ], [ "x", "y", "z" ] ];
var group = [];
for ( var i = 0; i &lt; NUM_EXPRESSIONS; i++ ) {
group.push( variables.shift().slice( 0, NUM_TERMS[ i ] ) );
}
return group;
})()
</var>
<var id="VALUES">[ randRangeNonZero( -10, 10 ), randRangeNonZero( -10, 10 ) ]</var>
<var id="FACTORS" data-ensure="FACTORS[0] !== 1 && FACTORS[1] !== 1">[ randRangeNonZero( -10, 10 ), randRangeNonZero( -10, 10 ) ]</var>
<var id="ORIGINAL_EXPRESSIONS">
(function() {
var originals = [];
$.each( GROUPS, function( index, group ) {
var coeffs = COEFFICIENTS[ index ];
var o = [];
$.each( group, function( i, variable ) {
o.push( expr( [ "*", coeffs[ i ], variable] ) );
});
originals.push( o );
});
return originals;
})()
</var>
<var id="MULTIPLIED_EXPRESSIONS">
(function() {
var expression = [];
$.each( GROUPS, function( index, group ) {
var coeffs = COEFFICIENTS[ index ];
$.each( group, function( i, variable ) {
expression.push( expr( [ "*", (coeffs[ i ] * FACTORS[ index ] ), variable ] ) );
});
});
return expression;
})()
</var>
<var id="QUESTION">shuffle( MULTIPLIED_EXPRESSIONS ).join( " + " )</var>
<var id="ANSWER">
(function() {
var answer = 0;
for ( var i = 0; i &lt; NUM_EXPRESSIONS; i++ ) {
answer += ( FACTORS[ i ] * VALUES[ i ] );
}
return answer;
})()
</var>
</div>
<div class="problems">
<div>
<div class="question">
<p>If <code><var>ORIGINAL_EXPRESSIONS[ 0 ].join( " + " )</var> = <var>VALUES[ 0 ]</var></code> <span data-if="NUM_EXPRESSIONS === 2">and <code><var>ORIGINAL_EXPRESSIONS[ 1 ].join( " + " )</var> = <var>VALUES[ 1 ]</var></code></span>,</p>
<p>what is <code><var>QUESTION</var></code>?</p>
</div>
<p class="solution"><var>ANSWER</var></p>
</div>
</div>
<div class="hints">
<p><code>= <var>MULTIPLIED_EXPRESSIONS.join( " + " )</var></code></p>
<p><code>= (<var>FACTORS[ 0 ]</var>) \cdot (<var>ORIGINAL_EXPRESSIONS[ 0 ].join( " + " )</var>)
<span data-if="NUM_EXPRESSIONS === 2"> + (<var>FACTORS[ 1 ] </var>) \cdot (<var>ORIGINAL_EXPRESSIONS[ 1 ].join( " + " )</var>)</span></code></p>
<p><code>= (<var>FACTORS[ 0 ]</var>) \cdot (<var> VALUES[ 0 ]</var>)
<span data-if="NUM_EXPRESSIONS === 2"> + (<var>FACTORS[ 1 ]</var>) \cdot (<var> VALUES[ 1 ]</var>)</span></code></p>
<p data-if="NUM_EXPRESSIONS === 2"><code>= <var>FACTORS[ 0 ] * VALUES[ 0 ]</var> + <var>FACTORS[ 1 ] * VALUES[ 1 ]</var></code></p>
<p><code>= <var>ANSWER</var></code>
</p></div>
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.