Permalink
Browse files

fixed errors where statements were duplicated in proof, hints were un…

…defined
  • Loading branch information...
mwittels committed Jul 9, 2012
1 parent 853771f commit 76d3b77365e191a60bb860ebc1700c27fb9a8ea5
Showing with 123 additions and 32 deletions.
  1. +1 −1 exercises/geometry_proofs_1.html
  2. +1 −1 exercises/geometry_proofs_2.html
  3. +40 −14 exercises/geometry_proofs_intro.html
  4. +81 −16 utils/proofs.js
@@ -47,7 +47,7 @@
<var id="ED">DE</var>
- <var id="SEGS">[AB,BA,AC,CA,AD,DA,AE,EA,BC,CB,BD,DB,CD,DC,CE,EC,DE,ED]</var>
+ <var id="SEGS">[AB,BA,AC,CA,AD,DA,AE,EA,BC,CB,BD,DB,BE,EB,CD,DC,CE,EC,DE,ED]</var>
<var id="ang1">new Ang("D","A","C", null)</var>
<var id="ang2">new Ang("C","A","B", null)</var>
@@ -415,7 +415,7 @@
<var id="ED">DE</var>
- <var id="SEGS">[AB,BA,AC,CA,AD,DA,AE,EA,BC,CB,BD,DB,CD,DC,CE,EC,DE,ED]</var>
+ <var id="SEGS">[AB,BA,AC,CA,AD,DA,AE,EA,BC,CB,BD,DB,BE,EB,CD,DC,CE,EC,DE,ED]</var>
<var id="ang1">new Ang("D","A","C", null)</var>
<var id="ang2">new Ang("C","A","B", null)</var>
@@ -148,30 +148,53 @@
$(".hint2").hide();
$(".hint3").hide();
- var hint = "you haven't entered anything!";
+ var hint = nextStatementHint();
$(".nextStatement input").keyup(function(){
- var triangles = [];
- triangles[0] = $("#thing1").val();
- triangles[1] = $("#thing2").val();
+ var thing1 = $("#thing1").val().toUpperCase();
+ var thing2 = $("#thing2").val().toUpperCase();
var reason = $("#reason").val();
- var verify = verifyStatementArgs(triangles[0]+"="+triangles[1], reason, "triangle congruence");
- if(verify.length > 0){
- hint = verify;
- }
- else if(!verify){
- hint = "you've put in triangles that are in the figure, but your reason isn't right.";
+ if(thing1.length === 0 && thing2.length === 0){
+ hint = nextStatementHint();
+ return;
}
- else{
- hint = "you've already finished! Hit the check answer button."
+
+ var verifyTriangles = verifyStatementArgs(thing1+"="+thing2, reason, "triangle congruence");
+ var verifyAngles = verifyStatementArgs(thing1+"="+thing2, reason, "angle equality");
+ var verifySegments = verifyStatementArgs(thing1+"="+thing2, reason, "segment equality");
+
+ if(verifyTriangles === true || verifyAngles === true || verifySegments === true){
$(".statements").html(outputKnownProof());
_.each($(".statements code"), function(tag){ $.tmpl.type.code()(tag); });
- $(".nextStatement").hide();
+ console.log("thinks statement is true");
+ $("#thing1").val("");
+ $("#thing2").val("");
+ $("#reason").val("");
+ if(userProofDone === true){
+ $(".nextStatement").hide();
+ $("#hint").attr("disabled", true);
+ }
+ else{
+ hint = nextStatementHint();
+ }
+ }
+ else if(verifyTriangles === false || verifyAngles === false || verifySegments === false){
+ hint = nextStatementHint();
+ }
+ else{
+ hint = "The things you've entered aren't valid segments, angles, or triangles in the figure.";
}
console.log(hint);
});
$("#reason").change(function(){
+ var curVal = $("#reason").val();
+ if(curVal === "SSS" || curVal === "ASA" || curVal === "SAS" || curVal === "AAS"){
+ $("#symbol1").html(" \\triangle ");
+ $("#symbol2").html(" \\triangle ");
+ }
+ $("#symbol1").html(" \\angle ");
+ $.tmpl.type.code()($("#symbol1")[0]);
$(".nextStatement input").keyup();
});
@@ -195,13 +218,16 @@
<p class="statements"> <var> outputKnownProof() </var></p>
<p class="nextStatement">
- <code> \bigtriangleup </code> <input type="text" id="thing1"></input> <code> = \bigtriangleup </code> <input type="text" id="thing2" > </input> because
+ <code id="symbol1"></code> <input type="text" id="thing1"></input> <code> \cong </code> <code id="symbol2"></code> <input type="text" id="thing2" > </input> because
<select id="reason">
<option value="">select a reason</option>
<option value="SSS">side-side-side congruence</option>
<option value="ASA">angle-side-angle congruence</option>
<option value="SAS">side-angle-side congruence</option>
<option value="AAS">angle-angle-side congruence</option>
+ <option value="vertical angles">vertical angles are equal</option>
+ <option value="alternate angles">alternate interior angles are equal</option>
+ <option value="CPCTC">corresp. parts of congruent triangles are congruent</option>
</select>
</p>
<div class="customHints">
View
@@ -373,7 +373,7 @@ function nextStatementHint() {
}
}
- return "Sorry, no hint for now >:[";
+ return "Sorry, there seems to be a problem with the hint system. Please report this bug.";
}
@@ -382,8 +382,9 @@ function nextStatementHint() {
function outputFinishedProof() {
var proofText = "<h3>Givens</h3>";
- var unsortedKeyList = _.map(finishedEqualitiesList, function(key) { return key.toString(); });
- var finishedKeys = sortEqualityList(unsortedKeyList.reverse(), finishedEqualities);
+ var unsortedKeyList = _.clone(finishedEqualitiesList);
+ var finishedKeysList = sortEqualityList(unsortedKeyList.reverse(), finishedEqualities);
+ var finishedKeys = _.map(finishedKeysList, function(key) { return key.toString(); });
var possibleValids = [];
@@ -432,7 +433,7 @@ function outputFinishedProof() {
function outputKnownProof() {
var proofText = "<h3>Givens</h3>";
- var knownKeys = sortEqualityList(_.keys(knownEqualities), knownEqualities);
+ var knownKeys = sortEqualityStringList(_.keys(knownEqualities), knownEqualities);
var numberGivens = 0;
_.each(knownKeys, function(key) {
@@ -478,20 +479,20 @@ function outputFillBlanksProof() {
var blanks = 0;
var blankStatements = 0;
- var unsortedKeyList = _.map(finishedEqualitiesList, function(key) { return key.toString(); });
- var finishedKeys = sortEqualityList(unsortedKeyList.reverse(), finishedEqualities);
+ var unsortedKeyList = _.clone(finishedEqualitiesList);
+ var finishedKeysList = sortEqualityList(unsortedKeyList.reverse(), finishedEqualities);
+ var finishedKeys = _.map(finishedKeysList, function(key) { return key.toString(); });
var numberGivens = 0;
_.each(finishedKeys, function(key) {
if (finishedEqualities[key] === "given") {
numberGivens++;
}
});
- numberGivens /= 2;
var newEqualities = {};
- for (var i = 0; i < finishedKeys.length; i += 2) {
+ for (var i = 0; i < finishedKeys.length; i++) {
if (finishedEqualities[finishedKeys[i]].substring(0, 4) != "Same") {
if (finishedEqualities[finishedKeys[i]] === "given") {
numberGivens--;
@@ -574,7 +575,7 @@ function checkFillBlanksStatement(divID) {
// for now, hardcode these
var equivAngles = {"BAE" : "BAC", "EAB" : "CAB", "DAE" : "DAC", "EAD" : "CAD", "ABD" : "ABC", "DBA" : "CBA", "EBD" : "EBC", "DBE" : "CBE",
"BEA" : "BEC", "AEB" : "CEB", "DEA" : "DEC", "AED" : "CED", "BDE" : "CDE", "EDB" : "EDC", "ADB" : "ADC", "BDA" : "CDA"};
- var unsortedKeyList = _.map(finishedEqualitiesList, function(key) { return _.clone(key); });
+ var unsortedKeyList = _.clone(finishedEqualitiesList);
var finishedKeys = sortEqualityList(unsortedKeyList.reverse(), finishedEqualities);
var components = divID.split("-");
@@ -687,7 +688,7 @@ function checkFillBlanksReason(select, selectID) {
// for fill-in-the-blanks proofs, this hint function looks for the next missing reason, and generate a hint based
// on that using nextStatementHint()
function getFillBlanksHint(giveAway) {
- var unsortedKeyList = _.map(finishedEqualitiesList, function(key) { return _.clone(key); });
+ var unsortedKeyList = _.clone(finishedEqualitiesList);
var finishedKeys = sortEqualityList(unsortedKeyList.reverse(), finishedEqualities);
if (!giveAway) {
@@ -702,6 +703,17 @@ function getFillBlanksHint(giveAway) {
for (var i = 0; i < finishedKeys.length; i++) {
beforeEqualities[finishedKeys[i]] = finishedEqualities[finishedKeys[i]];
}
+ for (var i = 0; i < SEGMENTS.length; i++) {
+ beforeEqualities[[SEGMENTS[i], SEGMENTS[i]]] = "Same segment";
+ }
+
+ for (var i = 0; i < ANGLES.length; i++) {
+ beforeEqualities[[ANGLES[i], ANGLES[i]]] = "Same angle";
+ }
+
+ for (var i = 0; i < TRIANGLES.length; i++) {
+ beforeEqualities[[TRIANGLES[i], TRIANGLES[i]]] = "Same triangle";
+ }
if (components[0] === "t") {
var triangle1 = finishedKeys[components[1]][0];
@@ -906,7 +918,7 @@ function outputBadProof() {
// now construct the proof we want to hand to the exercise
var proofText = "<h3>Givens</h3>";
- var knownKeys = sortEqualityList(_.keys(knownEqualities), knownEqualities);
+ var knownKeys = sortEqualityStringList(_.keys(knownEqualities), knownEqualities);
var numberGivens = 0;
_.each(knownKeys, function(key) {
@@ -1443,7 +1455,7 @@ function traceBack(statementKey, depth) {
var trianglePair = newTriangles[KhanUtil.randRange(0, newTriangles.length - 1)];
// there has to be a better way of doing this
- // _indexOf doesn't work (because of === issues?)
+ // _.indexOf doesn't work (because of === issues?)
var index1;
for (var i = 0; i < trianglePair[0].segs.length; i++) {
if (trianglePair[0].segs[i].equals(seg1)) {
@@ -1918,7 +1930,7 @@ function checkTriangleForHint(triangle1, triangle2, equalityObject) {
&& eqIn([triangle1.angs[(i + 1) % 3], triangle2.angs[(i + 1) % 3]], equalityObject)
&& eqIn([triangle1.segs[(i + 2) % 3], triangle2.segs[(i + 2) % 3]], equalityObject)) {
return [[triangle1.angs[i], triangle2.angs[i]],
- [triangle1.segs[(i + 2) % 3], triangle2.segs[(i + 2) % 3]], [triangle1.segs[(i + 2) % 3], triangle2.segs[(i + 2) % 3]]];
+ [triangle1.angs[(i + 1) % 3], triangle2.angs[(i + 1) % 3]], [triangle1.segs[(i + 2) % 3], triangle2.segs[(i + 2) % 3]]];
}
}
@@ -1944,13 +1956,27 @@ function checkSegForHint(seg1, seg2, equalityObject) {
// return [];
// }
-
for (var i = 0; i < seg1.triangles.length; i++) {
for (var j = 0; j < seg2.triangles.length; j++) {
+ var index1;
+ for (var k = 0; k < seg1.triangles[i][0].segs.length; k++) {
+ if (seg1.triangles[i][0].segs[k].equals(seg1)) {
+ index1 = k;
+ }
+ }
+
+ var index2;
+ for (var k = 0; k < seg2.triangles[j][0].segs.length; k++) {
+ if (seg2.triangles[j][0].segs[k].equals(seg2)) {
+ index2 = k;
+ }
+ }
+
// if the segments' corresponding triangles are congruent AND they're the same part of those triangles, we add
// to the known equalities
if (eqIn([seg1.triangles[i][0], seg2.triangles[j][0]], equalityObject)
- && _.indexOf(seg1, seg1.triangles[i][0].segs) === _.indexOf(seg2, seg2.triangles[j][0].segs)) {
+ && index1 === index2) {
+
return [seg1.triangles[i][0], seg2.triangles[j][0]];
}
}
@@ -1969,8 +1995,23 @@ function checkAngForHint(ang1, ang2, equalityObject) {
// to the known
for (var i = 0; i < ang1.triangles.length; i++) {
for (var j = 0; j < ang2.triangles.length; j++) {
+
+ var index1;
+ for (var k = 0; k < ang1.triangles[i][0].angs.length; k++) {
+ if (ang1.triangles[i][0].angs[k].equals(ang1)) {
+ index1 = k;
+ }
+ }
+
+ var index2;
+ for (var k = 0; k < ang2.triangles[j][0].angs.length; k++) {
+ if (ang2.triangles[j][0].angs[k].equals(ang2)) {
+ index2 = k;
+ }
+ }
+
if (eqIn([ang1.triangles[i][0], ang2.triangles[j][0]], equalityObject)
- && _.indexOf(ang1, ang1.triangles[i][0].angs) === _.indexOf(ang2, ang2.triangles[j][0].angs)) {
+ && index1 === index2) {
return [ang1.triangles[i][0], ang2.triangles[j][0]];
}
}
@@ -2097,6 +2138,30 @@ function triangIn(item, object) {
// also, since we add the vertical angles and alternate angles before the triangles they prove, we need to move these
// forward in the list
function sortEqualityList(equalityList, equalityObject) {
+ var dupCheck = {};
+ var newEqualityList = [];
+ for (var i = 0; i < equalityList.length; i++) {
+ if (equalityObject[equalityList[i]] === "given" && !(equalityList[i] in dupCheck || equalityList[i].reverse() in dupCheck)) {
+ newEqualityList.unshift(equalityList[i]);
+ dupCheck[equalityList[i]] = true;
+ }
+ else if(!(equalityList[i] in dupCheck || equalityList[i].reverse() in dupCheck)) {
+ newEqualityList.push(equalityList[i]);
+ dupCheck[equalityList[i]] = true;
+ }
+ }
+ var sortedEqualityList = _.clone(newEqualityList);
+ for (var i = 0; i < newEqualityList.length; i++) {
+ if (equalityObject[newEqualityList[i]] === "vertical angles are equal" || equalityObject[newEqualityList[i]] === "alternate interior angles are equal") {
+ sortedEqualityList[i - 1] = newEqualityList[i];
+ sortedEqualityList[i] = newEqualityList[i - 1];
+ }
+ }
+
+ return sortedEqualityList;
+}
+
+function sortEqualityStringList(equalityList, equalityObject) {
var newEqualityList = [];
for (var i = 0; i < equalityList.length; i++) {
if (equalityObject[equalityList[i]] === "given") {

0 comments on commit 76d3b77

Please sign in to comment.