Permalink
Browse files

Make factoring_polynomials_by_grouping_1 accept all valid answers

fix #38994; fix #38162; fix #35332; fix #35331

Test plan: Load http://localhost:8000/exercises/factoring_polynomials_by_grouping_1.html?debug&problem=0&seed=88 and try all of these answers:
    (-7x-1)(x-5)
    (-7x-1)(-5+x)
    (-1-7x)(x-5)
    (-1-7x)(-5+x)
    (x-5)(-7x-1)
    (-5+x)(-7x-1)
    (x-5)(-1-7x)
    (-5+x)(-1-7x)
    (7x+1)(-x+5)
    (7x+1)(5-x)
    (1+7x)(-x+5)
    (1+7x)(5-x)
    (-x+5)(7x+1)
    (5-x)(7x+1)
    (-x+5)(1+7x)
    (5-x)(1+7x)
    -(7x+1)(x-5)
    -(7x+1)(-5+x)
    -(1+7x)(x-5)
    -(1+7x)(-5+x)
    -(-x+5)(-7x-1)
    -(5-x)(-7x-1)
    -(-x+5)(-1-7x)
    -(5-x)(-1-7x)
    -(7x+1)(x-5)
    -(7x+1)(-5+x)
    -(1+7x)(x-5)
    -(1+7x)(-5+x)
    -(-x+5)(-7x-1)
    -(5-x)(-7x-1)
    -(-x+5)(-1-7x)
    -(5-x)(-1-7x)

Auditors: cbhl, alpert
  • Loading branch information...
1 parent 56c4b61 commit 66a5ed8e156d65f3ec3b779c4957a0c6991b85f3 @beneater beneater committed Mar 6, 2013
Showing with 40 additions and 5 deletions.
  1. +40 −5 exercises/factoring_polynomials_by_grouping_1.html
@@ -15,6 +15,14 @@
<var id="F">randRangeNonZero(-5, 5)</var>
<var id="B">E + A * F</var>
<var id="C">E * F</var>
+ <var id="AX_PLUS_E">"\\(\\s*" + (A &lt; 0 ? "[-\u2212]" : "") + abs(A) + "[xX]\\s*" + (E &lt; 0 ? "[-\u2212]" : "\\+") + "\\s*" + abs(E) + "\\s*\\)"</var>
+ <var id="E_PLUS_AX">"\\(\\s*" + (E &lt; 0 ? "[-\u2212]" : "") + "\\s*" + abs(E) + (A &lt; 0 ? "[-\u2212]" : "") + abs(A) + "[xX]\\s*" + "\\s*\\)"</var>
+ <var id="X_PLUS_F">"\\(\\s*[xX]\\s*" + (F &lt; 0 ? "[-\u2212]" : "\\+") + "\\s*" + abs(F) + "\\s*\\)"</var>
+ <var id="F_PLUS_X">"\\(\\s*" + (F &lt; 0 ? "[-\u2212]" : "") + "\\s*" + abs(F) + "\\s*\\+\\s*[xX]\\s*\\)"</var>
+ <var id="NEG_AX_MINUS_E">"\\(\\s*" + (A &gt; 0 ? "[-\u2212]" : "") + abs(A) + "[xX]\\s*" + (E &gt; 0 ? "[-\u2212]" : "\\+") + "\\s*" + abs(E) + "\\s*\\)"</var>
+ <var id="NEG_E_MINUS_AX">"\\(\\s*" + (E &gt; 0 ? "[-\u2212]" : "") + "\\s*" + abs(E) + "\\s*" + (A &gt; 0 ? "[-\u2212]" : "\\+") + abs(A) + "\\s*[xX]\\s*" + "\\s*\\)"</var>
+ <var id="NEG_X_MINUS_F">"\\(\\s*[-\u2212]\\s*[xX]\\s*" + (F &gt; 0 ? "[-\u2212]" : "\\+") + "\\s*" + abs(F) + "\\s*\\)"</var>
+ <var id="NEG_F_MINUS_X">"\\(\\s*" + (F &gt; 0 ? "[-\u2212]" : "") + "\\s*" + abs(F) + "\\s*[-\u2212]\\s*[xX]\\s*\\)"</var>
</div>
<p class="problem">Factor the following expression:</p>
@@ -23,12 +31,39 @@
<span id="question-b"><code><var>B</var></code></span><code>x<span data-if="C > 0">+</span></code>
<span id="question-c"><code><var>C</var></code></span>
</p>
-
<div class="solution" data-type="set">
- <div class="set-sol" data-type="regex">^\s*\(\s*<var>A &lt; 0 ? "[-\u2212]" : ""</var><var>abs(A)</var>[xX]\s*<var>E &lt; 0 ? "[-\u2212]" : "\\+"</var>\s*<var>abs(E)</var>\s*\)\s*\(\s*[xX]\s*<var>F &lt; 0 ? "[-\u2212]" : "\\+"</var>\s*<var>abs(F)</var>\s*\)\s*$</div>
- <div class="set-sol" data-type="regex">^\s*\(\s*[xX]\s*<var>F &lt; 0 ? "[-\u2212]" : "\\+"</var>\s*<var>abs(F)</var>\s*\)\s*\(\s*<var>A &lt; 0 ? "[-\u2212]" : ""</var><var>abs(A)</var>[xX]\s*<var>E &lt; 0 ? "[-\u2212]" : "\\+"</var>\s*<var>abs(E)</var>\s*\)\s*$</div>
- <div class="set-sol" data-type="regex">^\s*\(\s*<var>A &gt; 0 ? "[-\u2212]" : ""</var><var>abs(A)</var>[xX]\s*<var>E &gt; 0 ? "[-\u2212]" : "\\+"</var>\s*<var>abs(E)</var>\s*\)\s*\(\s*[-\u2212][xX]\s*<var>F &gt; 0 ? "[-\u2212]" : "\\+"</var>\s*<var>abs(F)</var>\s*\)\s*$</div>
- <div class="set-sol" data-type="regex">^\s*\(\s*[-\u2212][xX]\s*<var>F &gt; 0 ? "[-\u2212]" : "\\+"</var>\s*<var>abs(F)</var>\s*\)\s*\(\s*<var>A &gt; 0 ? "[-\u2212]" : ""</var><var>abs(A)</var>[xX]\s*<var>E &gt; 0 ? "[-\u2212]" : "\\+"</var>\s*<var>abs(E)</var>\s*\)\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>AX_PLUS_E</var>\s*<var>X_PLUS_F</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>AX_PLUS_E</var>\s*<var>F_PLUS_X</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>E_PLUS_AX</var>\s*<var>X_PLUS_F</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>E_PLUS_AX</var>\s*<var>F_PLUS_X</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>X_PLUS_F</var>\s*<var>AX_PLUS_E</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>F_PLUS_X</var>\s*<var>AX_PLUS_E</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>X_PLUS_F</var>\s*<var>E_PLUS_AX</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>F_PLUS_X</var>\s*<var>E_PLUS_AX</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>NEG_AX_MINUS_E</var>\s*<var>NEG_X_MINUS_F</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>NEG_AX_MINUS_E</var>\s*<var>NEG_F_MINUS_X</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>NEG_E_MINUS_AX</var>\s*<var>NEG_X_MINUS_F</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>NEG_E_MINUS_AX</var>\s*<var>NEG_F_MINUS_X</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>NEG_X_MINUS_F</var>\s*<var>NEG_AX_MINUS_E</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>NEG_F_MINUS_X</var>\s*<var>NEG_AX_MINUS_E</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>NEG_X_MINUS_F</var>\s*<var>NEG_E_MINUS_AX</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*<var>NEG_F_MINUS_X</var>\s*<var>NEG_E_MINUS_AX</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_AX_MINUS_E</var>\s*<var>X_PLUS_F</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_AX_MINUS_E</var>\s*<var>F_PLUS_X</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_E_MINUS_AX</var>\s*<var>X_PLUS_F</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_E_MINUS_AX</var>\s*<var>F_PLUS_X</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_X_MINUS_F</var>\s*<var>AX_PLUS_E</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_F_MINUS_X</var>\s*<var>AX_PLUS_E</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_X_MINUS_F</var>\s*<var>E_PLUS_AX</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_F_MINUS_X</var>\s*<var>E_PLUS_AX</var>\s*$</div>
@petercollingridge

petercollingridge Mar 13, 2013

Member

The eight solutions below are the same as the eight solutions above. I guess the order of the variables was meant to be swapped to capture all possible answers. Currently they don't, e.g. Issue #43280

+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_AX_MINUS_E</var>\s*<var>X_PLUS_F</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_AX_MINUS_E</var>\s*<var>F_PLUS_X</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_E_MINUS_AX</var>\s*<var>X_PLUS_F</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_E_MINUS_AX</var>\s*<var>F_PLUS_X</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_X_MINUS_F</var>\s*<var>AX_PLUS_E</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_F_MINUS_X</var>\s*<var>AX_PLUS_E</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_X_MINUS_F</var>\s*<var>E_PLUS_AX</var>\s*$</div>
+ <div class="set-sol" data-type="regex">^\s*[-\u2212]\s*<var>NEG_F_MINUS_X</var>\s*<var>E_PLUS_AX</var>\s*$</div>
<div class="input-format"><span class="entry"></span></div>
<div class="example">a factored expression, like <b>(2x+1)(x+2)</b></div>
</div>

0 comments on commit 66a5ed8

Please sign in to comment.