libLIST=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libLIST.m"]<>"\n";
libNAMES=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libNAMES.m"]<>"\n";
libIO=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libIO.m"]<>"\n";
libERR=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libERR.m"]<>"\n";
libGUI=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libGUI.m"]<>"\n";
libML=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libML.m"]<>"\n";
libMISC=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libMISC.m"]<>"\n";

(* TODO: add more variations *)
data="\n"<>"textfghjkl:="<>ToString[{

(* question *)
{"Column[{ToString[\"fghjkl. Suppose ther is a linear relationship between distance driven @a and the annual cost of owning, a car, @b, in one year.\",TraditionalForm]"<>","<>"makeTextTable[{{\"Km driven\n      x\",\"Annual costs \nof owning a car in $\n           y \"},{#i0,#j0},{#i1,#j1},{#i2,#j2},{#i3,#j3}}]"(*"\"\""*)<>"}]",

"Column[{ToString[\"fghjkl. Suppose ther is a linear relationship between distance driven @a and the annual cost of owning, a car, @b, in one year.\",TraditionalForm]"<>","<>"makeTextTable[{{\"Km driven\n      x \",\"Annual costs \nof owning a car in $\n          y \"},{#i0,#j0},{#i1,#j1},{#i2,#j2},{#i3,#j3}}]"(*"\"\""*)<>"}]"},

(*a*)
{"ToString[\"Start with solving \"<>If[UpperCaseQ[\"FGHJKLabc\"],\"B\",\"b\"]<>\") and after return to solve FGHJKLabc). \nFGHJKLabc) Find the missing values from table.\",TraditionalForm]",
"ToString[\"Start with solving \"<>If[UpperCaseQ[\"FGHJKLabc\"],\"B\",\"b\"]<>\") and after return to solve FGHJKLabc). \nFGHJKLabc) Find the missing values in the chart.\",TraditionalForm]"},

(*b*)
(*{"Column[{ToString[\"FGHJKLabc) State the slope in the equation relating the total cost to the distance given in the form y = mx + b.\"]"<>"}]", 
"Column[{ToString[\"FGHJKLabc) Find the slope in the equation relating the total cost to the distance given in the form y = mx + b.\"]"<>"}]"},*)
{"Column[{ToString[\"FGHJKLabc) Compute m and b in the equation y = mx + b relating the totall cost to distance traveled.\"]"<>","<>"ToString[\"Give an answer in order m b and separate answer using only one space e.g.: 4 2\",TraditionalForm]}]", 

"Column[{ToString[\"FGHJKLabc) Determine m and b in the equation y = mx + b relating the totall cost to distance traveled.\"]"<>","<>"ToString[\"Give an answer in order m b and separate answer using only one space e.g.: 4 2\",TraditionalForm]}]"},

(*c*)
{"ToString[\"FGHJKLabc) Explain in words what the slope represents in context of this question.\",TraditionalForm]",
"ToString[\"FGHJKLabc) What does the slope mean in context of this question? Explain it in words.\",TraditionalForm]"},


(*d*)
{"Column[{ToString[\"FGHJKLabc) What is the y-intercept in given line equation y = mx + b?\"]"<>"}]", 
"Column[{ToString[\"FGHJKLabc) Compute the y-intercept in given line equation y = mx + b.\"]"<>"}]"},

(*e*)
{"ToString[\"FGHJKLabc) What does y-intercept mean in words? \",TraditionalForm]", 
"ToString[\"FGHJKLabc) Explain in words what y-intercept means in the context of this question.\",TraditionalForm]"},

(*f*)
{"ToString[\"FGHJKLabc) If a new model is believed to better describe the relationship between distanse and annual cost of owning a car, and the new model is given by @b = #m@a \",TraditionalForm]<>If[ToExpression[#z]==0,\"\",If[ToExpression[#z]<0,ToString[\"#z\",TraditionalForm],ToString[\"+#z\",TraditionalForm] ]]<> ToString[\". Determine Km driven such that the annual costs of owning a car will be the same for both models.\",TraditionalForm]"}

},InputForm]<>";\n ";

variation1=data<>ToString[Hold[Module[{p,a,b,c,d,e,f,g,h,i,j,i0,j0,i1,i2,i3,j1,j2,j3,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,jj0,jj1,jj2,jj3, vars,text,list,sol, parta, partb, partc, partd,parte,partf,question,x,missing,tmp,m,z,table,locs,init,init2,mnew},


question=qRandList[textfghjkl[[1]]];

text=qRandList[textfghjkl[[2]]];

(*p={"a","a"};
While[p[[1]]===p[[2]],p=nLetters[{"a","z"},2] /.{"b"->"c","m"->"n"}]; 
{aa,bb}=p;*)
{aa,bb}={"x","y"};

(*y=cx+d, in table x = 1 and x = e*)
(*{c,d}=nIntegers[not0/@Range[2,10],2];*)

{c}=nIntegers[not0/@Range[2,6],1];
{d}=ToString/@nIntegers[not0/@Range[10,30],1];

e=ToString[RandomInteger[{3000,7000}]];
init=RandomInteger[{1000,2000}];
init2=RandomInteger[{2000,7000}];
{i0,j0,i1,j1,i2,j2,i3,j3}=ToString/@{0,ToExpression[d],init,IntegerPart[ToExpression[c]*init+ToExpression[d]],ToExpression[e],ToExpression[c]*ToExpression[e]+ToExpression[d],(ToExpression[e]+init2),ToExpression[c]*(ToExpression[e]+init2)+ToExpression[d]};

missing=RandomSample[Range@4,2]; (* take two random integer between 1 to 4 *)



{jj0, jj1,jj2,jj3}={j0,j1,j2,j3};
tmp={jj0, jj1,jj2,jj3};
tmp[[missing[[1]]]]="\"?\"";
tmp[[missing[[2]]]]="\"?\"";
{jj0, jj1,jj2,jj3}=tmp;


table={{ToString["Km driven\n      x",InputForm],ToString["Annual costs of owning a car in $\n      y",InputForm]},{i0,j0},{i1,j1},{i2,j2},{i3,j3}};
locs={{missing[[1]]+1,2},{missing[[2]]+1,2}};
sol={table[[locs[[1]][[1]],locs[[1]][[2]] ]],table[[locs[[2]][[1]],locs[[2]][[2]] ]]};

vars={table,locs,aa,bb,c,d,e,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing};

question=StringReplace[question, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#i0"->i0,"#i1"->i1,"#j0"->jj0,"#j1"->jj1,"#i2"->i2,"#j2"->jj2,"#i3"->i3,"#j3"->jj3}];

parta={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#i1"->i1,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#j3"->j3}],vars,sol} ;

(* b*)

text=qRandList[textfghjkl[[3]]];

(*Which[missing=={1,2} || missing=={2,1},sol=ToString[{ToExpression[d],ToExpression[c]*1+ToExpression[d]},InputForm],
missing=={1,3}|| missing=={3,1},sol=ToString[{ToExpression[d],ToExpression[c]*ToExpression[e]+ToExpression[d]},InputForm],
missing=={1,4}|| missing=={4,1},sol=ToString[{ToExpression[d],ToExpression[c]*(ToExpression[e]+3)+ToExpression[d]},InputForm],
missing=={2,3}|| missing=={3,2},sol=ToString[{ToExpression[c]*1+ToExpression[d],ToExpression[c]*ToExpression[e]+ToExpression[d]},InputForm],
missing=={2,4}|| missing=={4,2},sol=ToString[{ToExpression[c]*1+ToExpression[d],ToExpression[c]*(ToExpression[e]+3)+ToExpression[d]},InputForm],
missing=={3,4}|| missing=={4,3},sol=ToString[{ToExpression[c]*ToExpression[e]+ToExpression[d],ToExpression[c]*(ToExpression[e]+3)+ToExpression[d]},InputForm]
];*)
sol= ToString[{ToExpression[c],ToExpression[d]},InputForm];
vars={aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing};
partb={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#f"->f,"#i0"->i0,"#i1"->i1,"#j0"->j0,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#i3"->i3,"#j3"->j3}],vars,sol} ;

(* c*)
text=qRandList[textfghjkl[[4]]];


vars={aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing};
sol=c;

partc={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#f"->f,"#i0"->i0,"#i1"->i1,"#j0"->j0,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#i3"->i3,"#j3"->j3}],vars,sol} ;

(* d*)
text=qRandList[textfghjkl[[5]]];

(*Which[missing=={1,2} || missing=={2,1},sol=ToString[{ToExpression[d],ToExpression[c]*1+ToExpression[d]},InputForm],
missing=={1,3}|| missing=={3,1},sol=ToString[{ToExpression[d],ToExpression[c]*ToExpression[e]+ToExpression[d]},InputForm],
missing=={1,4}|| missing=={4,1},sol=ToString[{ToExpression[d],ToExpression[c]*(ToExpression[e]+3)+ToExpression[d]},InputForm],
missing=={2,3}|| missing=={3,2},sol=ToString[{ToExpression[c]*1+ToExpression[d],ToExpression[c]*ToExpression[e]+ToExpression[d]},InputForm],
missing=={2,4}|| missing=={4,2},sol=ToString[{ToExpression[c]*1+ToExpression[d],ToExpression[c]*(ToExpression[e]+3)+ToExpression[d]},InputForm],
missing=={3,4}|| missing=={4,3},sol=ToString[{ToExpression[c]*ToExpression[e]+ToExpression[d],ToExpression[c]*(ToExpression[e]+3)+ToExpression[d]},InputForm]
];*)
sol= ToString[ToExpression[d],InputForm];
vars={aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing};
partd={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#f"->f,"#i0"->i0,"#i1"->i1,"#j0"->j0,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#i3"->i3,"#j3"->j3}],vars,sol} ;


(* e*)
text=qRandList[textfghjkl[[6]]];

sol=ToString[d]; 

vars={aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing};

parte={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#f"->f,"#i0"->i0,"#i1"->i1,"#j0"->j0,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#i3"->i3,"#j3"->j3}],vars,sol} ;

(* f*)
text=qRandList[textfghjkl[[7]]];

(*ANNA: please fix m and z ; y=mx+z*)
(*m=ToString[ToExpression[c]+1];*)
z=ToString[RandomInteger[{ToExpression[d]-7,ToExpression[d]-1}]];
mnew=ToExpression[nIntegers[Divisors[ToExpression[d]-ToExpression[z]],1][[1]]];
m=ToString@(mnew+ToExpression[c]);

sol=ToString[(ToExpression[d]-ToExpression[z]) / (ToExpression[m] - ToExpression[c])];


vars={aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,m,z, sol,missing};
partf={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#f"->f,"#i0"->i0,"#i1"->i1,"#j0"->j0,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#i3"->i3,"#j3"->j3,"#m"->m,"#z"->z}],vars,sol} ;


{{question,parta[[1]], partb[[1]],partc[[1]],partd[[1]],parte[[1]],partf[[1]]},{parta[[2]], partb[[2]],partc[[2]],partd[[2]],parte[[2]],partf[[2]]}, {parta[[3]], partb[[3]],partc[[3]],partd[[3]],parte[[3]],partf[[3]]}}

(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution1=data<>ToString[Hold[Module[{aa,bb,cc,dd,ee, c,d,e,ff,f, gg, hh, ii, jj,i0,j0,i3,i1,i2,j1,j2,j3, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,varsf,index,missing,m,z,table, locs,toeq},




varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];
varsd=vars[[4]];
varse=vars[[5]];
varsf=vars[[6]];

body={
{options[[1]]<>":" ,options[[2]]<>":", options[[3]]<>":",options[[4]]<>":",options[[5]]<>":",options[[6]]<>":"},
({
(*a*)
{table, locs, aa,bb,c,d,e,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing}=varsa;" \n"<>
Which[
missing=={1,2} || missing=={2,1},
ToString[makeTextTable[{{"Km driven\n   x","Annual costs of \nowning a car in $\n      y"},{i0,i0<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j0,Red],TraditionalForm]},{i1,i1<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j1,Red],TraditionalForm]},{i2,j2},{i3,j3}}],TraditionalForm],

missing=={1,3}|| missing=={3,1},
ToString[makeTextTable[{{"Km driven\n   x","Annual costs of \nowning a car in $\n      y"},{i0,i0<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j0,Red],TraditionalForm]},{i1,j1},{i2,i2<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j2,Red],TraditionalForm]},{i3,j3}}],TraditionalForm],

missing=={1,4}|| missing=={4,1},
ToString[makeTextTable[{{"Km driven\n   x","Annual costs of \nowning a car in $\n      y"},{i0,i0<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j0,Red],TraditionalForm]},{i1,j1},{i2,j2},{i3,i3<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j3,Red],TraditionalForm]}}],TraditionalForm],

missing=={2,3}|| missing=={3,2},
ToString[makeTextTable[{{"Km driven\n   x","Annual costs of \nowning a car in $\n      y"},{i0,j0},{i1,i1<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j1,Red],TraditionalForm]},{i2,i2<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j2,Red],TraditionalForm]},{i3,j3}}],TraditionalForm],

missing=={2,4}|| missing=={4,2},

ToString[makeTextTable[{{"Km driven\n   x","Annual costs of \nowning a car in $\n      y"},{i0,j0},{i1,i1<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j1,Red],TraditionalForm]},{i2,j2},{i3,i3<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j3,Red],TraditionalForm]}}],TraditionalForm],

missing=={3,4}|| missing=={4,3},

ToString[makeTextTable[{{"Km driven\n   x","Annual costs of \nowning a car in $\n      y"},{i0,j0},{i1,j1},{i2,i2<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j2,Red],TraditionalForm]},{i3,i3<>"("<>c<>") + "<>d<>" = "<>ToString[Style[j3,Red],TraditionalForm]}}],TraditionalForm]
],

(* b*)

{aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing}=varsb;

"\nm = "<>
Which[
missing=={1,2} || missing=={2,1},
ToString[(j3- j2)/(i3 - i2),TraditionalForm]<>" = "<>ToString[Simplify[(ToExpression[j3] -ToExpression[ j2])/(ToExpression[i3] - ToExpression[i2])],TraditionalForm],
missing=={1,3}|| missing=={3,1},
ToString[(j3 - j1)/(i3 - i1),TraditionalForm]<>" = "<>ToString[Simplify[(ToExpression[j3] -ToExpression[ j1])/(ToExpression[i3] - ToExpression[i1])],TraditionalForm],
missing=={1,4}|| missing=={4,1},
ToString[(j2 - j1)/(i2 - i1),TraditionalForm]<>" = "<>ToString[Simplify[(ToExpression[j2] -ToExpression[ j1])/(ToExpression[i2] - ToExpression[i1])],TraditionalForm],
missing=={2,3}|| missing=={3,2},
ToString[(j2 - j1)/(i2 - i1),TraditionalForm]<>" = "<>ToString[Simplify[(ToExpression[j2] -ToExpression[ j1])/(ToExpression[i2] - ToExpression[i1])],TraditionalForm],
missing=={2,4}|| missing=={4,2},
ToString[(j2 - j0)/(i2 - i0),TraditionalForm]<>" = "<>ToString[Simplify[(ToExpression[j2] -ToExpression[ j0])/(ToExpression[i2] - ToExpression[i0])],TraditionalForm],
missing=={3,4}|| missing=={4,3},
ToString[(j1 - j0)/(i1 - i0),TraditionalForm]<>" = "<>ToString[Simplify[(ToExpression[j1] -ToExpression[ j0])/(ToExpression[i1] - ToExpression[i0])],TraditionalForm]

]
<>"\n\n"<>
ToString[bb,TraditionalForm]<>" = "<> ToString[c,TraditionalForm]<>ToString[aa,TraditionalForm]<>" + b\n"<>

Which[
missing=={1,2} || missing=={2,1},
"Take point (x,y)=("<>i2<>","<>j2<>")\n"<>ToString[j2,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>" ("<>ToString[i2,TraditionalForm]<>") + b\n"<> 
ToString[j2,TraditionalForm]<>" - "<>ToString[ToExpression[c]*ToExpression[i2],TraditionalForm]<>" = b\n",

missing=={1,3}|| missing=={3,1},
"Take point (x,y)=("<>i1<>","<>j1<>")\n"<>ToString[j1,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>" ("<>ToString[i1,TraditionalForm]<>") + b\n"<> 
ToString[j1,TraditionalForm]<>" - "<>ToString[ToExpression[c]*ToExpression[i1],TraditionalForm]<>" = b\n",

missing=={1,4}|| missing=={4,1},
"Take point (x,y)=("<>i1<>","<>j1<>")\n"<>ToString[j1,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>" ("<>ToString[i1,TraditionalForm]<>") + b\n"<> 
ToString[j1,TraditionalForm]<>" - "<>ToString[ToExpression[c]*ToExpression[i1],TraditionalForm]<>" = b\n",

missing=={2,3}|| missing=={3,2},
"Take point (x,y)=("<>i3<>","<>j3<>")\n"<>ToString[j3,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>" ("<>ToString[i3,TraditionalForm]<>") + b\n"<> 
ToString[j3,TraditionalForm]<>" - "<>ToString[ToExpression[c]*ToExpression[i3],TraditionalForm]<>" = b\n",

missing=={2,4}|| missing=={4,2},
"Take point (x,y)=("<>i2<>","<>j2<>")\n"<>ToString[j2,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>" ("<>ToString[i2,TraditionalForm]<>") + b\n"<> 
ToString[j2,TraditionalForm]<>" - "<>ToString[ToExpression[c]*ToExpression[i2],TraditionalForm]<>" = b\n",
missing=={3,4}|| missing=={4,3},
"Take point (x,y)=("<>i1<>","<>j1<>")\n"<>ToString[j1,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>" ("<>ToString[i1,TraditionalForm]<>") + b\n"<> 
ToString[j1,TraditionalForm]<>" - "<>ToString[ToExpression[c]*ToExpression[i1],TraditionalForm]<>" = b\n"
]

<>"b = "<>ToString[d,TraditionalForm]<>
"\n Answer: "<>ToString[c,TraditionalForm]<>" "<>ToString[d,TraditionalForm]<>"\n",

(* c *)
{aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing}=varsc;
"\nSample:\nThe annual costs of owning a car\n increases by $"<>c<>" per km driven. \n",

(* d*)
{aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing}=varsd;
"\n y-intercept = b ="<>ToString[d,TraditionalForm]<>"\n",

(* e*)
{aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,sol,missing}=varse;
""<>" \nSample:\n y-intercept is the cost of owning a car when 0 km are driven."<>"\n",

(*f*)
{aa,bb,c,d,e,f,i0,i1,j0,j1,i2,j2,i3,j3,m,z,sol,missing}=varsf;
toeq=If[ToExpression[z]==0,"",Which[ToExpression[z]<0,ToString[z,TraditionalForm],ToExpression[z]>0,ToString[" + "<>z,TraditionalForm] ]];
"Old model:\ny ="<>c<>" x + "<>d<>
"\n New model:\ny = "<>m<>" x"<>If[ToExpression[z]==0,"",Which[ToExpression[z]<0,ToString[z,TraditionalForm],ToExpression[z]>0,ToString[" + "<>z,TraditionalForm] ]]<>"\n"<>
ToString[({{\[Piecewise], ({{"y = "<>c<>" x + "<>d, "---- 1 "}, {"y = "<>m<>" x"<>toeq, "---- 2"}})}}),TraditionalForm]<>
"\n"<>ToString[tv[{"1",
"Method of Substitution\n"<>
"Substitute 2 into 1\n"<>m<>" x"<>toeq<>" = "<>c<>" x + "<>d<>"\n"<>
m<>"x - "<>c<>"x = "<>d<>If[ToExpression[z]==0,"",Which[ToExpression[z]<0,ToString[" + "<>ToString[Abs[ToExpression[z]],TraditionalForm],TraditionalForm],ToExpression[z]>0,ToString[" - "<>ToString[Abs[ToExpression[z]],TraditionalForm],TraditionalForm] ]]<>
"\n"<>If[ToExpression[m]-ToExpression[c]==1,"",ToString[IntegerPart[ToExpression[m]-ToExpression[c]],TraditionalForm]]<>" x = "<>ToString[ToExpression[d] - ToExpression[z],TraditionalForm]<>If[ToExpression[m]-ToExpression[c]≠1,"\n x = "<>ToString[(ToExpression[d] - ToExpression[z])/(ToExpression[m]-ToExpression[c]),TraditionalForm],""],
"2",
"Method of Elimination"<>"\nEliminate y by\nSubstracting 1 and 2\n"<>"    y ="<>c<>" x + "<>d<>
"\n"<>"- (y = "<>m<>" x"<>If[ToExpression[z]==0,"",Which[ToExpression[z]<0,ToString[z,TraditionalForm],ToExpression[z]>0,ToString[" + "<>z,TraditionalForm] ]]<>")"<>
"\n"<>"———————"<>
"\n"<>"  0 = "<>If[IntegerPart[ToExpression[c] - ToExpression[m]]==-1,"-",ToString[IntegerPart[ToExpression[c] - ToExpression[m]],TraditionalForm]]<>" x "<>If[(ToExpression[d] - ToExpression[z])==0,"",If[(ToExpression[d] - ToExpression[z])<0,ToString[ToExpression[d] - ToExpression[z],TraditionalForm], "+ "<>ToString[ToExpression[d] - ToExpression[z],TraditionalForm]]]<>
"\n"<>If[ToExpression[m]-ToExpression[c]==1,"",ToString[IntegerPart[ToExpression[m]-ToExpression[c]],TraditionalForm]]<>" x = "<>ToString[ToExpression[d] - ToExpression[z],TraditionalForm]<>If[ToExpression[m]-ToExpression[c]≠1,"\n x = "<>ToString[(ToExpression[d] - ToExpression[z])/(ToExpression[m]-ToExpression[c]),TraditionalForm],""],
"3",
"Alternative Method of Elimination\n"<>m<>" x"<>toeq<>" = "<>c<>" x + "<>d<>"\n"<>
m<>"x - "<>c<>"x = "<>d<>If[ToExpression[z]==0,"",Which[ToExpression[z]<0,ToString[" + "<>ToString[Abs[ToExpression[z]],TraditionalForm],TraditionalForm],ToExpression[z]>0,ToString[" - "<>ToString[Abs[ToExpression[z]],TraditionalForm],TraditionalForm] ]]<>
"\n"<>If[ToExpression[m]-ToExpression[c]==1,"",ToString[IntegerPart[ToExpression[m]-ToExpression[c]],TraditionalForm]]<>" x = "<>ToString[ToExpression[d] - ToExpression[z],TraditionalForm]<>If[ToExpression[m]-ToExpression[c]≠1,"\n x = "<>ToString[(ToExpression[d] - ToExpression[z])/(ToExpression[m]-ToExpression[c]),TraditionalForm],""]
}],TraditionalForm]

})
};

Panel[Grid[Transpose[body]]] 

(*"Anna switch a and c"*)

]],InputForm]<>"\n ";


hint1=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},


body={
{ToString[Column[{
options[[1]]<>": \nIdentify which variable is given. Solve for the unknown\n", 
options[[2]]<> ": \nEquation of line: y = mx + b\nSolve for m an b \nm = "<>ToString[("(Subscript[y, 2]) - (Subscript[y, 1])")/("(Subscript[x, 2]) - (Subscript[x, 1])"),TraditionalForm]<>"\nTo find b, substitute m and a point (x,y) into y = mx + b\n",
options[[3]]<>": \nExpress slope as a \"rate\".\n", 
options[[4]]<>": \ny-intercept is parameter b. \n", 
options[[5]]<>": \nThink in terms of \"fixed cost\"\n",
options[[6]]<>": \nSet up system of equations.\nSolve by:\n"<>ToString[tv[{"1","Method of Substitution","2","Method of Elimination","3","Alternative Method of Elimination\n"}],TraditionalForm]
}],TraditionalForm]
}, 
{Null (*,Null, Null,Null,Null,Null*)}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

(*KLUDGE, needs to be generalized *)
qpanelMultiTABLE2=ToString[Hold[DynamicModule[{pn,proc,err,level0,max,mult,diag0,answer,myEnabled,A1,answerStudent,A2,a1,a2,level1,stateH=False,state=False,vars,xxx,yyy,text,sol,prev,again, variation,variation2,hint, solution, procs,first=True,options,io,answers},


Panel[Column[{

If[diag00==0 ||diag00==2,Panel[Row[{OpenerView[{Button["Try Again",
(*AppendTo[level1[[3]],prev];*)
first=ConstantArray[True,mult0+2];
level1=again;
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];
Table[A2[[i]]=ToString[bigNumber];
A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult0+2}];], ""}],
OpenerView[{Button["Hint",stateH=Not[stateH],Method->"Queued"],Dynamic[If[stateH==True,ReleaseHold[ToExpression[StringReplace[hint,{"ertyuiop"->ToString[vars,InputForm],ToUpperCase["ertyuiop"]->ToString[options,InputForm]}]]]]]},Dynamic[stateH]],
OpenerView[{Button["Solution",state=Not[state],Method->"Queued"],Dynamic[If[state==True,ReleaseHold[ToExpression[StringReplace[solution,{"ertyuiop"->ToString[vars,InputForm],ToUpperCase["ertyuiop"]->ToString[options,InputForm]}]]]]]},Dynamic[state]]}]],""],



Column[{Dynamic[ReleaseHold[ToExpression[text[[1]]/.{"fghjkl"->pn}]]]}~Join~{Dynamic[ReleaseHold[ToExpression[StringReplace[text[[2]],{"FGHJKLabc"->options[[1]]}]]]]}~Join~{(answers=Table[With[{i=i},


Column[{
Dynamic[A2[[i]]=If[TrueQ[A1[[i]]==Null], ToString[bigNumber],A1[[i]]];

(*FIXME: need a much better parsing and filtering, problem is with 6.6 and . as dot in a sentence *)
If[Length[StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]]==1, a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]][[1]],a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]];If[ToExpression[a2]===bigNumber,"", myEnabled[[i]]=False;
(*errNo set to the first for all *)
""<>Which[err[[i]][sol[[1]][[i]],a2,A1[[i]]]==True&&ToExpression[a2]=!=bigNumber, (*a2=!=ToString[bigNumber] to Avoid ToExpression*)


(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[i]]==True,"\!\(\*
StyleBox[\"Correct\",\nFontColor->RGBColor[1, 0, 0]]\)",
diag00==1,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"\!\(\*
StyleBox[\"Correct\",\nFontColor->RGBColor[1, 0, 0]]\)",True, ""],

err[[i]][sol[[1]][[i]],a2,A1[[i]]]==False&&ToExpression[a2]=!=bigNumber,

Which[diag00==0&&first[[i]]==True,"\!\(\*
StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)",
diag00==1,If[first[[i]]==True,io[pn,i,False,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,False,A1[[i]], diag00]];first[[i]]=False;"\!\(\*
StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)",True, ""],True,""]]],

Deploy@InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->inputsize0[[i]],FieldHint->"       ?",FieldHintStyle->{Red}]}] (*inputsize has to be written over here*)

],{i, 1,2}]);Dynamic@makeTextTable2[ToExpression[vars[[1]][[1]]],answers,ToExpression[vars[[1]][[2]]]]}],


Column[Table[With[{i=i},


Column[{If[mult0>1,Dynamic[ReleaseHold[ToExpression[StringReplace[text[[i+2-2]],{"FGHJKLabc"->options[[i+1-2]]}]]]]," "] ,
Dynamic[A2[[i]]=If[TrueQ[A1[[i]]==Null], ToString[bigNumber],A1[[i]]];

(*FIXME: need a much better parsing and filtering, problem is with 6.6 and . as dot in a sentence *)
If[Length[StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]]==1, a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]][[1]],a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]];If[ToExpression[a2]===bigNumber,"\nAnswer?", myEnabled[[i]]=False;"\nAnswer: "<>Which[err[[i]][sol[[i-2+1]],a2,A1[[i]]]==True&&ToExpression[a2]=!=bigNumber,  (*a2=!=ToString[bigNumber] to Avoid ToExpression*)


(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[i]]==True,"Correct",
diag00==1,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"Correct",True, ""],

err[[i]][sol[[i-2+1]],a2,A1[[i]]]==False&&ToExpression[a2]=!=bigNumber,

Which[diag00==0&&first[[i]]==True,"Incorrect",
diag00==1,If[first[[i]]==True,io[pn,i,False,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,False,A1[[i]], diag00]];first[[i]]=False;"Incorrect",True, ""],True,""]]],

Deploy@InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->inputsize0[[i]]]}] (*inputsize has to be written over here*)

],{i, 3,4+3}]]

}]],
(*{{level,Dynamic[level1[[1]]]},Range[max],ControlType->PopupMenu},*)
(*TrackedSymbols->Manipulate,(* SaveDefinitions->True,*)AppearanceElements->None,SynchronousUpdating->False,ContinuousAction->False,*)
Initialization:>(stateH=False;state=False;


libs; (* add the needed functions and constants *)


(* these are the parameters that used to be passed as argument list *)
(* FIXME: mult0 has to be written over by replacement and cannot be initialized here *)
pn=pn0;proc=proc0;err=ToExpression[err0];level0=level00;max=max0;mult=mult0+2;diag0=diag00;
io=ToExpression[IO00];

SetOptions[EvaluationNotebook[],DynamicEvaluationTimeout->100];
(* changing of the DynamicUpdateInterval did not alter anythin *)
(*SetOptions[EvaluationNotebook[],"DynamicUpdateInterval"->0.2];*)


(* the rest here sets up the math for the question *)
answer=ConstantArray[" ",mult];
A1=ConstantArray["",mult];
A2=ConstantArray[ToString[bigNumber],mult];
answerStudent=ConstantArray[" ",mult];
myEnabled=ConstantArray[True,mult];
first=ConstantArray[True,mult];

Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult}];
If[mult> 1,options=qRandList[{CharacterRange["a","z"][[1;;mult-2+1]],CharacterRange["A","Z"][[1;;mult-2+1]]}],options={" "}]; 


{again, variation, hint, solution}=proc;
again=ToExpression[again];
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];


level1=again;

)

]],InputForm]<>"\n";

CONFIGURATION AREA

proc1=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation1,hint1,solution1},InputForm]<>";\n";

ToExpression@libGUI;
(* this needs to be Expression make sure to set it always as expression*)
ToExpression@libML;
panelsMIX={StringReplace[qpanelMultiTABLE2,{"pn0"->ToString[1],"proc0"->proc1,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC<>"\n"<>libML<>"\n"<>libGUI),"err0"->"{errNO,errNO,errNO,err5,errNO,err6,errNO}","inputsize0"->"{5,5,5,30,5,30,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"5","diag00"->"0","IO00"->"qClick"}]};

CDF Area

CDFDeploy[ToFileName[{$UserDocumentsDirectory},"TRSM_LINE_PRAC.cdf"],Column[Table[ReleaseHold[ToExpression[panelsMIX[[i]]]],{i,1,Length[panelsMIX]}]],
"Method"->"Standalone"];

Test Area

Column[Table[ReleaseHold[ToExpression[panelsMIX[[i]]]],{i,1,Length[panelsMIX]}]]