Hi Marcus,
The maths I'm doing is really simple (upper primary/lower highschool level) but I'm trying to provie rich feedback and randomisation (hence STACK). The biggest thing I'm using the caschat for is the html and making sure that the layout and formatting of answers is appropriate. My html is improving but the nature of working within Moodle is a bit of a limiting factor so I'm becoming something of a master in 'worst-practice' html (all my styling is done in tags since we can't [at least I can't] do proper
css).
At present I'm playing with feedback for vertical subtraction so I'm using the caschat for stuff like the below. I write the maxima and html in Visual Studio Code, copy that across to the Caschat for testing, then in theory I can just put that straight into a question and have minimal tweaking/troubleshoting in the slower question interface... (At least that's the theory).
Question Variables:
n1: rand(9000)+1000;
n2: rand(9000)+1000;
aa: max(n1,n2);
bb: min(n1,n2);
ta: aa-bb;
colour1: red;
colour2: blue;
colour3: green;
digitlist(n) := if integerp(n) and n > -1 then digitlist_helper(n,[]);
digitlist_helper(n,acc) := block([p],
if n < 10 then cons(n,acc) else (
p : mod(n,10),
digitlist_helper(floor((n-p)/10), cons(p,acc))));
borrow(nnDigits,i) := block(
if(nnDigits[i]#9) then nnDigits[i]:nnDigits[i]+10,
if nnDigits[i-1]>0 then nnDigits[i-1]:nnDigits[i-1]-1
else block(nnDigits[i-1]:9,borrow(nnDigits,i-1)),
return(nnDigits)
)
aaDigits: digitlist(aa);
aaLen: length(aaDigits);
bbDigits: digitlist(bb);
taDigits: digitlist(ta);
debugString:"";
for i:1 while length(bbDigits) < aaLen do (
bbDigits: push(0,bbDigits)
);
for i:1 while length(taDigits) < aaLen do (
taDigits: push(0,taDigits)
);
borDigits: aaDigits;
for i:aaLen thru 1 step -1 do (
if borDigits[i]<bbDigits[i] then borDigits: borrow(borDigits,i)
else borDigits[i]:aaDigits[i],
debugString: sconcat("Step ",i,": ",borDigits, debugString)
)
aaDigits: digitlist(aa);
aaDigitsOriginal: digitlist(aa);
minuend :"<td style=\"min-width:40px;text-align:right;font-weight:bold;\"></td>";
for i:1 thru aaLen step 1 do (
td: sconcat("<td style=\"min-width:40px;text-align:right;font-weight:bold;\">",aaDigits[i],"</td>"),
minuend: sconcat(minuend, td)
)
minuend_bor :"<td style=\"min-width:40px;text-align:right;font-weight:bold;\"></td>";
borrowing: makelist(0,aaLen);
for i:1 thru aaLen step 1 do (
if aaDigits[i]=borDigits[i] then td: sconcat("<td style=\"min-width:40px;text-align:right;font-weight:bold;\">",aaDigits[i],"</td>")
else td: sconcat("<td style=\"color:",colour2,";min-width:40px;text-align:right;font-weight:bold;\"> <span style=\"color:",colour1,";text-decoration:line-through\">",aaDigits[i],"</span> ",borDigits[i]," </td>"),
borrowing[i]: td,
minuend_bor: sconcat(minuend_bor, td)
)
subtrahend :"<td style=\"min-width:40px;text-align:right;font-weight:bold;\">\\(-\\)</td>";
for i:1 thru aaLen step 1 do (
td: sconcat("<td style=\"min-width:40px;text-align:right;font-weight:bold;border-bottom: solid 1px black;\">",bbDigits[i],"</td>"),
subtrahend: sconcat(subtrahend, td)
)
ones: sconcat("<p>In the ones place, we have \\(", aaDigits[aaLen]," - ", bbDigits[aaLen],"\\)<p>")
if aaDigits[aaLen]>=bbDigits[aaLen] then ones: sconcat(ones,"<p>No borrowing is needed</p>")
else block(
ones: sconcat(ones,"<p>We need to borrow \\(10\\) from the tens place</p>"),
if aaDigits[aaLen-1]>0 then block(
ones:sconcat(ones, "<p>So we subtract one from \\(", aaDigits[aaLen-1], "\\) to get \\(", aaDigits[aaLen-1]-1, "\\) in the tens place and add \\(10\\) to the ones place.</p>", "<p>Now the ones place looks like:</p>", "<table><tbody><tr>", borrowing[aaLen], "</tr></tbody></table>"),
aaDigits[aaLen-1]: aaDigits[aaLen-1]-1,
aaDigits[aaLen]:aaDigits[aaLen]+10
)
else block(
ones:sconcat(ones, "<p>Since there are no tens, we need to borrow from the hundreds place</p>"),
if aaDigits[aaLen-2]>0 then block(
ones:sconcat(ones, "<p>So we subtract one from \\(", aaDigits[aaLen-2], "\\) to get \\(", aaDigits[aaLen-2]-1, "\\) in the hundreds place</p>","<p>We then put a \\(9\\) the tens place and add \\(10\\) to the ones place:</p>", "<table><tbody><tr>", borrowing[aaLen], "</tr></tbody></table>"),
aaDigits[aaLen-2]: aaDigits[aaLen-2]-1,
aaDigits[aaLen-1]: 9,
aaDigits[aaLen]:aaDigits[aaLen]+10
)
else block(
ones:sconcat(ones, "<p>Since there are no hundreds, we need to borrow from the thousands place</p>"),
if aaDigits[aaLen-3]>0 then block(
ones:sconcat(ones, "<p>So we subtract one from \\(", aaDigits[aaLen-3], "\\) to get \\(", aaDigits[aaLen-3]-1, "\\) in the thousands place</p>","<p>We then put a \\(9\\) in the hundreds place and a \\(9\\) in the tens place and add \\(10\\) to the ones place:</p>", "<table><tbody><tr>", borrowing[aaLen], "</tr></tbody></table>"),
aaDigits[aaLen-3]: aaDigits[aaLen-3]-1,
aaDigits[aaLen-2]: 9,
aaDigits[aaLen-1]: 9,
aaDigits[aaLen]:aaDigits[aaLen]+10
)
)
)
)
ones:sconcat(ones,"<p>\\(", aaDigits[aaLen]," - ", bbDigits[aaLen],"=\\)<span style=\"color:",colour3,";\">\\(",taDigits[aaLen],"\\)</span></p>");
tens: sconcat("<p>In the tens place, we have \\(", borDigits[aaLen-1]," - ", bbDigits[aaLen-1],"\\)<p>")
if aaDigits[aaLen-1]>=bbDigits[aaLen] then tens: sconcat(tens,"<p>No borrowing is needed</p>")
else block(
tens: sconcat(tens,"<p>We need to borrow \\(10\\) from the hundreds place</p>"),
if aaDigits[aaLen-2]>0 then tens:sconcat(tens, "<p>So we subtract one from \\(", aaDigits[aaLen-2], "\\) to get \\(", aaDigits[aaLen-2]-1, "\\) in the hundreds place add \\(10\\) to the tens place</p>", "<p>Now the tens place looks like:</p>", "<table><tbody><tr>", borrowing[aaLen-1], "</tr></tbody></table>")
else block(
tens:sconcat(tens, "<p>Since there are no hundreds, we need to borrow from the thousands place</p>"),
if aaDigits[aaLen-3]>0 then tens:sconcat(tens, "<p>So we subtract one from \\(", aaDigits[aaLen-3], "\\) to get \\(", aaDigits[aaLen-3]-1, "\\) in the thousands place</p>","<p>We then put a \\(9\\) the hundreds place and add \\(10\\) to the tens place:</p>", "<table><tbody><tr>", borrowing[aaLen-1], "</tr></tbody></table>")
)
)
Question Variables:
<table>
<tbody>
<tr>
{@minuend@}
</tr>
<tr>
{@subtrahend@}
</tr>
</tbody>
</table>
<br>
<br>
{@ones@}
<br>
{@tens@}
<br>
<br>
<p>After all borrowing is completed, the problem looks like:</p>
<table>
<tbody>
<tr>
{@minuend_bor@}
</tr>
<tr>
{@subtrahend@}
</tr>
</tbody>
</table>