Permalink
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (112 sloc) 3.65 KB
<!DOCTYPE html>
<html data-require="math kmatrix matrix-input">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Matrix addition and subtraction</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="MAT_A">randRange(-2, 4, ROWS, COLS)</var>
<var id="MAT_B">randRange(-2, 4, ROWS, COLS)</var>
<var id="OPERATION">randFromArray(["+", "-"])</var>
<var id="SOLN_MAT">
deepZipWith(2, function(a, b) {
if (OPERATION === "+") {
return a + b;
} else {
return a - b;
}
}, MAT_A, MAT_B)
</var>
<var id="PADDED_SOLN_MAT">matrixPad(SOLN_MAT, 3, 3)</var>
<var id="MAT_A_COLOR">BLUE</var>
<var id="MAT_B_COLOR">GREEN</var>
<var id="SOLN_MAT_COLOR">PINK</var>
<var id="PRETTY_MAT_A">
printSimpleMatrix(MAT_A, MAT_A_COLOR)
</var>
<var id="PRETTY_MAT_B">
printSimpleMatrix(MAT_B, MAT_B_COLOR)
</var>
<var id="PRETTY_HINT_MAT">
printMatrix(function(a, b) {
a = colorMarkup(a, MAT_A_COLOR);
b = colorMarkup(b, MAT_B_COLOR);
return a + OPERATION + b;
}, MAT_A, MAT_B)
</var>
<var id="PRETTY_SOLN_MAT">
printSimpleMatrix(SOLN_MAT, SOLN_MAT_COLOR)
</var>
</div>
<div class="question">
<code>
\Large{
<var>PRETTY_MAT_A + OPERATION + PRETTY_MAT_B</var> = {?}
}
</code>
</div>
<div class="hints">
<div>
<p>To find the
<span data-if="OPERATION === '+'">sum</span>
<span data-else="">difference</span>
of two matrices,
<span data-if="OPERATION === '+'">add</span>
<span data-else="">subtract</span>
the corresponding items between each matrix.
</p>
<div>
<code>\Large{<var>PRETTY_HINT_MAT</var>}</code>
</div>
</div>
<div>
<p>Now, simplify:</p>
<div>
<code>\Large{<var>PRETTY_SOLN_MAT</var>}</code>
</div>
</div>
</div>
<div class="solution" data-type="multiple">
<div class="matrix-row" data-each="PADDED_SOLN_MAT as row">
<span data-each="row as elem">
<span class="sol" data-forms="integer" data-if="elem !== ''">
<var>elem</var>
</span>
<span class="sol" data-else="" data-type="text">
<var>elem</var>
</span>
</span>
</div>
</div>
<div class="problems">
<div id="2x2">
<div class="vars" data-apply="prependVars">
<var id="ROWS">2</var>
<var id="COLS">2</var>
</div>
</div>
<div id="2x3">
<div class="vars" data-apply="prependVars">
<var id="ROWS">2</var>
<var id="COLS">3</var>
</div>
</div>
<div id="3x1">
<div class="vars" data-apply="prependVars">
<var id="ROWS">3</var>
<var id="COLS">1</var>
</div>
</div>
<div id="3x2">
<div class="vars" data-apply="prependVars">
<var id="ROWS">3</var>
<var id="COLS">2</var>
</div>
</div>
</div>
</div>
</body>
</html>