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";
libGraphics=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libGraphics.m"]<>"\n";
libMISC=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libMISC.m"]<>"\n";
libML=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Practice/libML.m"]<>"\n";

libLIST=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/TRSMREL/libLIST.m"]<>"\n";
libNAMES=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/TRSMREL/libNAMES.m"]<>"\n";
libIO=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/TRSMREL/libIO.m"]<>"\n";
libERR=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/TRSMREL/libERR.m"]<>"\n";
libGUI=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/TRSMREL/libGUI.m"]<>"\n";
libML=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/TRSMREL/libML.m"]<>"\n";
libMISC=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/TRSMREL/libMISC.m"]<>"\n";
libGraphics=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/TRSMREL/libGraphics.m"]<>"\n";

data="\n"<>"textfghjkl:="<>ToString[{
{"Column[{ToString[\"fghjkl. Answer the following:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]","Column[{ToString[\"fghjkl. Answer each question:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},


(*b*)
{"Column[{ToString[\" Solve for @a:\"]"<>","<>"ToString[\" #b(@a-#c)-#d(@a+#g)=#e \",TraditionalForm]}]",
"Column[{ToString[\" Find the value for @a:\"]"<>","<>"ToString[\"  #b(@a-#c)-#d(@a+#g)=#e  \",TraditionalForm]}]"},

(*c*)
{"Column[{ToString[\" Solve for @g: \",TraditionalForm]"<>","<>"If[ToExpression[\"#d\"]>=0,
ToString[ToString[(\"#a @g\")/(\"#b \"),TraditionalForm]<>\" = \"<>ToString[(\"#c @g + #d\")/\"#e\",TraditionalForm],TraditionalForm],
ToString[ToString[(\"#a @g\")/(\"#b \"),TraditionalForm]<>\" = \"<>ToString[(ToString[\"#c @g - \"<>ToString[Abs[ToExpression[\"#d\"]],TraditionalForm],TraditionalForm])/\"#e\",TraditionalForm],TraditionalForm]
]"<>"}]"}  ,

(*e*)
{"Column[{ToString[\" Solve for @g and @h\",TraditionalForm]"<>","<>
"Column[{
If[ToExpression[\"#b\"]>=0,
ToString[\"#a @g + #b @h = #c\",TraditionalForm],
ToString[\"#a @g #b @h = #c\",TraditionalForm]
]
,
If[ToExpression[\"#e\"]>=0,
ToString[\"#d @g + #e @h = #f\",TraditionalForm],
ToString[\"#d @g #e @h = #f\",TraditionalForm]
]
}]"<>"}]"}


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

canvas1="\n"<>ToString[Hold[canvasFunc1[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{
(*ToExpression@question[[1]],*)
ToExpression@text[[1]],
Column[{Row[{Column[{options[[1]]<>")",""}],ToExpression@text[[2]]}],Row[{vars[[2]][[1]][[1]]<>" = ",Column[{answers[[1]],""}]}]}] ,
(*makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,2],ToExpression@vars[[2]][[1]][[2]]],*)

Spacer@100,
Column[{Row[{Column[{options[[2]]<>")","",""}],ToExpression@text[[3]]}],Row[{vars[[2]][[2]][[7]]<>" = ",Column[{answers[[2]],""}]}]}],
Spacer@100,
Column[{Row[{Column[{options[[3]]<>")","",""}],ToExpression@text[[4]]}],Column[{
Row[{ToString@vars[[2]][[3]][[9]]<>" = ",Column[{answers[[3]],""}]}],
Row[{ToString@vars[[2]][[3]][[10]]<>" = ",Column[{answers[[4]],""}]}]
}]
}] 


}]


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




variation1=data<>ToString[Hold[Module[{p,x,a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp, vars,text,list,sol,aabbee,k, parta, partb, partc, partd,parte,partf,question,list12,teste},


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

(*b*)
text=qRandList[textfghjkl[[2]]];

{aa}=qRandList[{nLetters[{"a","y"},1]/.{"l"->"L","o"->"z"},nLetters[{"a","y"},1]/.{"l"->"L","o"->"z"}}]; 
(* bb*m +cc*(m-dd)=ee-gg*m *)
dd=ToString@RandomInteger[{2,12}];
bb=ToString@(ToExpression[dd]+RandomInteger[{3,7}]);
cc=ToString@RandomInteger[{2,12}];
gg=ToString@RandomInteger[{2,9}];
x=ToString@RandomInteger[{-10,10}];
ee=ToString@(ToExpression[x]*(ToExpression[bb]-ToExpression[dd]) - ToExpression[bb]*ToExpression[cc]-ToExpression[dd]*ToExpression[gg]);
(*{bb,cc,dd,ee}=nIntegers[not0/@Range[2,10],4];

(* use String@ to conver to String for 1 number, String/@{...} to covert a list *)
gg=ToString@(Abs[-ToExpression[bb]+ToExpression[cc]]+RandomInteger[{1,3}]);*)
vars={aa,bb,cc,dd,ee,gg,x};
sol=x;



partb={StringReplace[text, {"#c"->cc, "#d"->dd, "#a"->aa, "@a"->aa,"#b"->bb, "#c"->cc, "#g"->gg, "#e"->ee}],vars,sol(*If[Length[sol]≠0,ToString[x/.sol[[1]],InputForm], "No Solution"]*)} ;



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

{g}=qRandList[{nLetters[{"a","y"},1]/.{"l"->"L","o"->"z"},nLetters[{"a","y"},1]/.{"l"->"L","o"->"z"}}]; 


Off[Infinity::indet];

aabbee=DeleteDuplicates[RandomPrime[15,20]];
{aa,bb,ee}=ToString/@aabbee[[1;;3]];

cc=ToString@(ToExpression[ee]*ToExpression[nIntegers[Union[Range[-4,-1],Range[1,5]],1][[1]]]);

dd="0";
While[dd === "0",
dd=ToString[(ToExpression[aa]*ToExpression[ee] -ToExpression[ bb]*ToExpression[cc])*ToExpression[nIntegers[Union[Range[-3,-1],Range[1,2]],1][[1]]](*ANNA,TraditionalForm*)]
];
gg=ToString[(ToExpression[bb]*ToExpression[dd])/(ToExpression[aa]*ToExpression[ee] - ToExpression[bb]*ToExpression[cc])(*ANNA,TraditionalForm*)];

vars={aa,bb,cc,dd,ee,gg,g,h};

partc={StringReplace[text, {"#c"->cc, "#d"->dd, "#a"->aa, "@g"->g,"#b"->bb,   "#e"->ee}],vars,gg} ;


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

{g,h}=qRandList[{nLetters[{"a","y"},2]/.{"l"->"L","o"->"z"},nLetters[{"a","y"},2]/.{"l"->"L","o"->"z"}(*nLetters[{"α","ω"},2]/.{"π"->"A"}*)}]; 
teste=RandomInteger[{1,2}];
p={1(*aa*),1(*bb*),1(*dd*),1(*ee*)};
(*CRAMER'S RULE: determinant of matrix: aa*ee - bb*dd*) 
While[p[[1]]*p[[4]]-p[[2]]*p[[3]]==0,

list12=ToExpression/@nIntegers[Union[(*Range[-10,-2],*)Range[2,10]],3];
k=RandomChoice[{1,2}];(*k is to check if we have same variables or opossite 1 means are oposite (we add in solution), 2 means are similar( we  substract in solution)*)
If[k==1,
AppendTo[list12,-(list12[[2]])],
AppendTo[list12,list12[[2]]]
];(*AppendTo[list12,-(list12[[2]])];*)
p=list12
(*p={not0[RandomInteger[{-10,10}]],not0[RandomInteger[{-10,10}]],not0[RandomInteger[{-10,10}]],not0[RandomInteger[{-10,10}]]}*)
];
If[teste==1,(*to check close to which parameter we have similar variables*)
{ee,dd,bb,aa}=ToString/@p;
,
{aa,bb,dd,ee}=ToString/@p;
];
(*aa=ToString[not0[RandomInteger[{-10,10}]]];
bb=ToString[not0[RandomInteger[{-10,10}]]];
dd=ToString[not0[RandomInteger[{-10,10}]]];
ee=ToString[not0[RandomInteger[{-10,10}]]];*)
gg=ToString[not0[RandomInteger[{-10,10}]]];
hh=ToString[not0[RandomInteger[{-10,10}]]];
cc=ToString[ToExpression[aa]*ToExpression[gg]+ToExpression[bb]*ToExpression[hh]];
ff=ToString[ToExpression[dd]*ToExpression[gg]+ToExpression[ee]*ToExpression[hh]];

vars={aa,bb,cc,dd,ee,ff,gg,hh,g,h,teste,ToString@k};
sol={gg,hh};

parte={StringReplace[text, {"#c"->cc, "#d"->dd, "#a"->aa, "@g"->g,"@h"->h,"#b"->bb,   "#e"->ee,"#f"->ff,"#h"->hh}],vars,sol(*ToString[{ToExpression[gg],ToExpression[hh]},InputForm]*)} ;


vars=ToString[{{question, partb[[1]],partc[[1]],parte[[1]]},{ partb[[2]],partc[[2]],parte[[2]]}, { partb[[3]],partc[[3]],parte[[3]]}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ partb[[2]],partc[[2]],parte[[2]]}, { partb[[3]],partc[[3]],parte[[3]]}}
(*

{{question, partb[[1]],partc[[1]],parte[[1]]},{partb[[2]],partc[[2]],parte[[2]]}, {partb[[3]],partc[[3]],parte[[3]]}}*)

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


solution1=data<>ToString[Hold[Module[{x, a,b,c,d,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,varsf,g,h,pp,teste,bb1,list123,pos1,t11,t12,t21,t22,s1,s2,sum1,sum2,k},





varsb=vars[[1]];
varsc=vars[[2]];
varse=vars[[3]];


(*{aa,bb,cc,dd,ee,gg,pp}=varsa;
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];
*)


body={
{ToString[Column[{

(*b*)
{aa,bb,cc,dd,ee,gg,x}=varsb; 
options[[1]]<>": \n"<>bb<>"("<>aa<>" - "<>cc<>") - "<>dd<>"("<>aa<>" + "<>gg<>") = "<>ee<>"\n"<>
bb<>aa<>" - "<>ToString[ToExpression[bb]*ToExpression[cc]]<>" - "<>dd<>aa<>" - "<>ToString[ToExpression[dd]*ToExpression[gg],TraditionalForm]<>" = "<>ee<>"\n"<>
ToString[ToExpression[bb] -ToExpression[ dd],TraditionalForm]<>aa<>" - "<>ToString[ToExpression[bb]*ToExpression[cc]+ToExpression[dd]*ToExpression[gg]]<>" = "<>ee<>"\n"<>
ToString[ToExpression[bb] -ToExpression[ dd],TraditionalForm]<>aa<>" = "<>ToString[ToExpression[ee]+ToExpression[bb]*ToExpression[cc]+ToExpression[dd]*ToExpression[gg]]<>"\n"<>aa<>" = "<>x<>"\n"
,  

(*c*)
{aa,bb,cc,dd,ee,gg,g,h}=varsc; 
options[[2]]<>": \n"<>
ToString[(aa<>g)/bb,TraditionalForm]<>" = "<>ToString[(ToString[cc*g,TraditionalForm]<>If[ToExpression[dd]>0," + "<>dd," - "<>ToString[Abs[ToExpression[dd]],TraditionalForm]])/(ToString[ee,TraditionalForm]),TraditionalForm]<>"\n"<>
ToString[ee,TraditionalForm]<>"("<>aa<>g<>") = "<>bb<>"("<>ToString[cc*g,TraditionalForm]<>If[ToExpression[dd]>0," + "<>ToString[dd,TraditionalForm]," - "<>ToString[Abs[ToExpression[dd]],TraditionalForm]]<>")\n"<>
(*3*)
ToString[ToExpression[ee]*ToExpression[aa],TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>ToString[ToExpression[cc]*ToExpression[bb],TraditionalForm]<>ToString[g,TraditionalForm]<>If[(ToExpression[dd]*ToExpression[bb]>0)," + "<>ToString[Abs[ToExpression[bb]*ToExpression[dd]],TraditionalForm]," - "<>ToString[Abs[ToExpression[bb]*ToExpression[dd]],TraditionalForm]]<>"\n"<>
(*4*)
ToString[ToExpression[ee]*ToExpression[aa]-ToExpression[cc]*ToExpression[bb],TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>If[(ToExpression[dd]*ToExpression[bb]>0),ToString[Abs[ToExpression[bb]*ToExpression[dd]],TraditionalForm],ToString[ToExpression[bb]*ToExpression[dd],TraditionalForm]]<>"\n"<>
ToString[g,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]<>"\n"



}],TraditionalForm]
,


(*e*)
{aa,bb,cc,dd,ee,ff,gg,hh,g,h,teste,k}=varse; 
bb1=ToString[Abs[ToExpression[bb]]];
options[[3]]<>": \n"<>ToString[tv[{"Method 1",
"Method of Substitustion\n"<>ToString[({{\[Piecewise], ({{g<>" = "<>ToString[(1/aa),TraditionalForm]<>"("<>cc<>If[ToExpression[bb]>0," - "," + "]<>bb1<>h<>")", "····· 1"}, {dd<>g<>If[ToExpression[ee]>0," + ",""]<>ee<>h<>" = "<>ff, "····· 2"}})}}),TraditionalForm]<>"\n"<>
"Substitute 1 into 2"<>"\n"<>
dd<>"["<>ToString[(1/aa),TraditionalForm]<>"("<>cc<>If[ToExpression[bb]>0," - "," + "]<>bb1<>h<>")"<>"]"<>If[ToExpression[ee]>0," + ",""]<>ee<>h<>" = "<>ff<>"  ······ × "<>aa<>"\n"<>
dd<>"("<>cc<>If[ToExpression[bb]>0," - "," + "]<>bb1<>h<>")"<>If[ToExpression[ee]*ToExpression[aa]>0," + ",""]<>ToString[ToExpression[ee]*ToExpression[aa],TraditionalForm]<>h<>" = "<>ToString[ToExpression[aa]*ToExpression[ff]]<>"\n"<>

ToString[ToExpression[dd]*ToExpression[cc],TraditionalForm]<>If[ToExpression[bb]*ToExpression[dd]>0," - "," + "]<>ToString[Abs[ToExpression[dd]*ToExpression[bb]]]<>h<>If[ToExpression[ee]*ToExpression[aa]>0," + ",""]<>ToString[ToExpression[ee]*ToExpression[aa],TraditionalForm]<>h<>" = "<>ToString[ToExpression[aa]*ToExpression[ff]]<>"\n"<>

ToString[ToExpression[dd]*(-ToExpression[bb]) + ToExpression[ee]*ToExpression[aa]]<>h<>" = "<>ToString[ToExpression[aa]*ToExpression[ff] - ToExpression[dd]*ToExpression[cc]]<>"\n"<>




ToString[h,TraditionalForm]<>" = "<>ToString[hh,TraditionalForm]<>"\n\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>If[ToExpression[bb]>0," + ",""]<>ToString[bb,TraditionalForm]<>"("<>ToString[hh(*gg*),TraditionalForm]<>") = "<>ToString[cc,TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>ToString[cc,TraditionalForm]<>If[ToExpression[hh]*ToExpression[bb]>0," - "," + "]<>ToString[Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>If[ToExpression[hh]*ToExpression[bb]>0,ToString[ToExpression[cc]-Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm],ToString[ToExpression[cc]+Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]]<>"\n"<>
ToString[g,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]<>"\n\n"<>
ToString[g,TraditionalForm]<>", "<>ToString[h,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]<>" "<>ToString[hh,TraditionalForm]
,
"Method 2",
"Method of Elimination\n"<>ToString[({{\[Piecewise], ({{aa<>g<>If[ToExpression[bb]>0," + ",""]<>bb<>h<>" = "<>cc, "····· 1"}, {dd<>g<>If[ToExpression[ee]>0," + ",""]<>ee<>h<>" = "<>ff, "····· 2"}})}}),TraditionalForm]<>"\n"<>
If[ToExpression[k]==1,"Add 1 and 2 :","Substract 1 and 2 :"]<>

"\n"<>

Which[teste==1,
(*bb<>h<>" + ("<>ee<>h<>") = "<>ToString[ToExpression[cc]+ToExpression[ff],TraditionalForm]<>"\n"<>*)
If[ToExpression[k]==1,
ToString[ToExpression[bb]+ToExpression[ee],TraditionalForm]<>h<>" = "<>ToString[ToExpression[cc]+ToExpression[ff],TraditionalForm],
ToString[ToExpression[bb]-ToExpression[ee],TraditionalForm]<>h<>" = "<>ToString[ToExpression[cc]-ToExpression[ff],TraditionalForm]
]<>"\n"<>

ToString[h,TraditionalForm]<>" = "<>ToString[hh,TraditionalForm]<>"\n\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>If[ToExpression[bb]>0," + ",""]<>ToString[bb,TraditionalForm]<>"("<>ToString[hh(*gg*),TraditionalForm]<>") = "<>ToString[cc,TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>ToString[cc,TraditionalForm]<>If[ToExpression[hh]*ToExpression[bb]>0," - "," + "]<>ToString[Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>If[ToExpression[hh]*ToExpression[bb]>0,ToString[ToExpression[cc]-Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm],ToString[ToExpression[cc]+Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]]<>"\n"<>
ToString[g,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]

,
teste==2,
(*aa<>g<>" + ("<>dd<>g<>") = "<>ToString[ToExpression[cc]+ToExpression[ff],TraditionalForm]<>"\n"<>*)
If[ToExpression[k]==1,
ToString[ToExpression[aa]+ToExpression[dd],TraditionalForm]<>g<>" = "<>ToString[ToExpression[cc]+ToExpression[ff],TraditionalForm],
ToString[ToExpression[aa]-ToExpression[dd],TraditionalForm]<>g<>" = "<>ToString[ToExpression[cc]-ToExpression[ff],TraditionalForm]
]<>"\n"<>
g<>" = "<>gg<>"\n\n"<>

aa<>"("<>gg<>")"<>If[ToExpression[bb]>0," + ",""]<>bb<>h<>" = "<>cc<>"\n"<>
bb<>h<>" = "<>ToString[cc,TraditionalForm]<>If[ToExpression[aa]*ToExpression[gg]>0," - "," + "]<>ToString[Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm]<>"\n"<>
ToString[bb,TraditionalForm]<>ToString[h,TraditionalForm]<>" = "<>If[ToExpression[aa]*ToExpression[gg]>0,ToString[ToExpression[cc]-Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm],ToString[ToExpression[cc]+Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm]]<>"\n"<>
ToString[h,TraditionalForm]<>" = "<>ToString[hh,TraditionalForm]

]<>"\n\n"<>
ToString[g,TraditionalForm]<>", "<>ToString[h,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]<>" "<>ToString[hh,TraditionalForm],

"Method 3",
"Alternative Method of Elimination\n"<>
(*ToString[({{\[Piecewise], ({{aa<>g<>If[ToExpression[bb]>0," + ",""]<>bb<>h<>" = "<>cc, "····· 1"}, {dd<>g<>If[ToExpression[ee]>0," + ",""]<>ee<>h<>" = "<>ff, "····· 2"}})}}),TraditionalForm]<>"\n"<>*)
If[ToExpression[k]==2,
If[teste==1,
"Isolate "<>aa<>g<>"\n"<>
ToString[({{\[Piecewise], ({{aa<>g<>" = "<>cc<>If[ToExpression[bb]>0," - "," + "]<>ToString[Abs[ToExpression[bb]],TraditionalForm]<>h, "····· 1"}, {dd<>g<>" = "<>ff<>If[ToExpression[ee]>0," - "," + "]<>ToString[Abs[ToExpression[ee]],TraditionalForm]<>h, "····· 2"}})}}),TraditionalForm]<>"\n"<>
cc<>If[ToExpression[bb]>0," - "," + "]<>ToString[Abs[ToExpression[bb]],TraditionalForm]<>h<>" = "<>ff<>If[ToExpression[ee]>0," - "," + "]<>ToString[Abs[ToExpression[ee]],TraditionalForm]<>h<>"\n"<>
ToString[ToExpression[bb]-ToExpression[ee],TraditionalForm]<>h<>" = "<>ToString[ToExpression[cc]-ToExpression[ff],TraditionalForm]<>"\n"<>
h<>" = "<>hh<>"\n\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>If[ToExpression[bb]>0," + ",""]<>ToString[bb,TraditionalForm]<>"("<>ToString[hh(*gg*),TraditionalForm]<>") = "<>ToString[cc,TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>ToString[cc,TraditionalForm]<>If[ToExpression[hh]*ToExpression[bb]>0," - "," + "]<>ToString[Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>If[ToExpression[hh]*ToExpression[bb]>0,ToString[ToExpression[cc]-Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm],ToString[ToExpression[cc]+Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]]<>"\n"<>
ToString[g,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]

,
"Isolate "<>bb<>h<>"\n"<>
ToString[({{\[Piecewise], ({{bb<>h<>" = "<>cc<>If[ToExpression[aa]>0," - "," + "]<>ToString[Abs[ToExpression[aa]],TraditionalForm]<>g, "····· 1"}, {ee<>h<>" = "<>ff<>If[ToExpression[dd]>0," - "," + "]<>ToString[Abs[ToExpression[dd]],TraditionalForm]<>g, "····· 2"}})}}),TraditionalForm]<>"\n"<>
cc<>If[ToExpression[aa]>0," - "," + "]<>ToString[Abs[ToExpression[aa]],TraditionalForm]<>g<>" = "<>ff<>If[ToExpression[dd]>0," - "," + "]<>ToString[Abs[ToExpression[dd]],TraditionalForm]<>g<>"\n"<>
ToString[ToExpression[aa]-ToExpression[dd],TraditionalForm]<>g<>" = "<>ToString[ToExpression[cc]-ToExpression[ff],TraditionalForm]<>"\n"<>
g<>" = "<>gg<>"\n\n"<>

aa<>"("<>gg<>")"<>If[ToExpression[bb]>0," + ",""]<>bb<>h<>" = "<>cc<>"\n"<>
bb<>h<>" = "<>ToString[cc,TraditionalForm]<>If[ToExpression[aa]*ToExpression[gg]>0," - "," + "]<>ToString[Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm]<>"\n"<>
ToString[bb,TraditionalForm]<>ToString[h,TraditionalForm]<>" = "<>If[ToExpression[aa]*ToExpression[gg]>0,ToString[ToExpression[cc]-Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm],ToString[ToExpression[cc]+Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm]]<>"\n"<>
ToString[h,TraditionalForm]<>" = "<>ToString[hh,TraditionalForm]

]
,
If[teste==1,
ToString[({{\[Piecewise], ({{aa<>g<>If[ToExpression[bb]>0," + ",""]<>bb<>h<>" = "<>cc, "····· 1 ×(-1)"}, {dd<>g<>If[ToExpression[ee]>0," + ",""]<>ee<>h<>" = "<>ff, "····· 2"}})}}),TraditionalForm]<>"\n"<>
ToString[({{\[Piecewise], ({{ToString[(-1)*ToExpression[aa],TraditionalForm]<>g<>If[(ToExpression[bb]*(-1))>0," + ",""]<>ToString[(-1)*ToExpression[bb],TraditionalForm]<>h<>" = "<>ToString[(-1)*ToExpression[cc],TraditionalForm], "····· 1 "}, {dd<>g<>If[ToExpression[ee]>0," + ",""]<>ee<>h<>" = "<>ff, "····· 2"}})}}),TraditionalForm]<>"\n"<>
"Isolate "<>dd<>g<>"\n"<>
ToString[({{\[Piecewise], ({{ToString[(-1)*ToExpression[aa],TraditionalForm]<>g<>" = "<>ToString[(-1)*ToExpression[cc],TraditionalForm]<>" - ("<>ToString[(-1)*ToExpression[bb],TraditionalForm]<>h<>")", "····· 1 "}, {dd<>g<>" = "<>ff<>" - ("<>ee<>h<>")", "····· 2"}})}}),TraditionalForm]<>"\n"<>
ToString[(-1)*ToExpression[cc],TraditionalForm]<>" - ("<>ToString[(-1)*ToExpression[bb],TraditionalForm]<>h<>") = "<>ff<>" - ("<>ee<>h<>")\n"<>
h<>" = "<>hh<>"\n\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>If[ToExpression[bb]>0," + ",""]<>ToString[bb,TraditionalForm]<>"("<>ToString[hh(*gg*),TraditionalForm]<>") = "<>ToString[cc,TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>ToString[cc,TraditionalForm]<>If[ToExpression[hh]*ToExpression[bb]>0," - "," + "]<>ToString[Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>If[ToExpression[hh]*ToExpression[bb]>0,ToString[ToExpression[cc]-Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm],ToString[ToExpression[cc]+Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]]<>"\n"<>
ToString[g,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]


,

ToString[({{\[Piecewise], ({{aa<>g<>If[ToExpression[bb]>0," + ",""]<>bb<>h<>" = "<>cc, "····· 1"}, {dd<>g<>If[ToExpression[ee]>0," + ",""]<>ee<>h<>" = "<>ff, "····· 2 ×(-1)"}})}}),TraditionalForm]<>"\n"<>
ToString[({{\[Piecewise], ({{aa<>g<>If[ToExpression[bb]>0," + ",""]<>bb<>h<>" = "<>cc, "····· 1"}, {ToString[(-1)*ToExpression[dd],TraditionalForm]<>g<>If[(ToExpression[ee]*(-1))>0," + ",""]<>ToString[(-1)*ToExpression[ee],TraditionalForm]<>h<>" = "<>ToString[(-1)*ToExpression[ff],TraditionalForm], "····· 2 "}})}}),TraditionalForm]<>"\n"<>
"Isolate "<>bb<>h<>"\n"<>
ToString[({{\[Piecewise], ({{bb<>h<>" = "<>cc <>" - ("<> aa<>g<>")", "····· 1"}, {ToString[(-1)*ToExpression[ee],TraditionalForm]<>h<>" = "<>ToString[(-1)*ToExpression[ff],TraditionalForm]<>" - ("<>ToString[(-1)*ToExpression[dd],TraditionalForm]<>g<>")", "····· 2 "}})}}),TraditionalForm]<>"\n"<>
cc <>" - ("<> aa<>g<>") = "<>ToString[(-1)*ToExpression[ff],TraditionalForm]<>" - ("<>ToString[(-1)*ToExpression[dd],TraditionalForm]<>g<>")\n"<>
g<>" = "<>gg<>"\n\n"<>

aa<>"("<>gg<>")"<>If[ToExpression[bb]>0," + ",""]<>bb<>h<>" = "<>cc<>"\n"<>
bb<>h<>" = "<>ToString[cc,TraditionalForm]<>If[ToExpression[aa]*ToExpression[gg]>0," - "," + "]<>ToString[Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm]<>"\n"<>
ToString[bb,TraditionalForm]<>ToString[h,TraditionalForm]<>" = "<>If[ToExpression[aa]*ToExpression[gg]>0,ToString[ToExpression[cc]-Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm],ToString[ToExpression[cc]+Abs[ToExpression[aa]*ToExpression[gg]],TraditionalForm]]<>"\n"<>
ToString[h,TraditionalForm]<>" = "<>ToString[hh,TraditionalForm]


]]<>"\n\n"<>ToString[g,TraditionalForm]<>", "<>ToString[h,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]<>" "<>ToString[hh,TraditionalForm]

}],TraditionalForm]

}, 
{Null ,Null} 
};


Panel[Grid[Transpose[body]]]

]],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]]<>": \n"<>"Expand and collect like terms.\nVariables on one side = Number on the other side\n",
options[[2]]<>": \n"<>"Use cross multiplication (a/b) = (x/c) ⟹ x = (ac/b)\n",
options[[3]]<>": \n"<>"Solve by:\n"<>ToString[tv[{"Method 1","Method of Substitustion","Method 2","Method of Elimination","Method 3","Alternative Method of Elimination"}],TraditionalForm]
}],TraditionalForm]
},
{Null}
};

Panel[Grid[Transpose[body]]]

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

data1="\n"<>"textfghjkl:="<>ToString[

{"Column[{fghjkl"<>".ToString[\"In a certain @aa, the ratio of those paid at the higher rate to those paid at the lower rate is #a:#b. If people are paid $#c at the higher rate and $#d at the lower rate and the total paid out each hour to all employees is $#e, determine @bb in the @aa. \"]"<>","<>"ToString[\"\",TraditionalForm]}]",

(* higher lower and c and d are swapped *)
"Column[{fghjkl"<>".ToString[\"In a certain @aa, the ratio of those paid at the higher rate to those paid at the lower rate is #a:#b. If people are paid $#d at the lower rate and $#c at the higher rate and the total paid out each hour to all employees is $#e, determine @bb in the @aa. \"]"<>","<>"ToString[\"\",TraditionalForm]}]"},
InputForm]<>";\n ";

data2="listfghjkl:="<>


ToString[{"hotel","corporation","business"

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

data=ToString[{data1, data2}, InputForm];

canvas2="\n"<>ToString[Hold[canvasFunc2[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{
(*ToExpression@question[[1]],*)
ToExpression@text[[1]],
Column[{answers[[1]]}] (*,
(*makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,2],ToExpression@vars[[2]][[1]][[2]]],*)

Spacer@100,
Column[{Row[{Column[{options[[2]]<>")","",""}],ToExpression@text[[3]]}],answers[[2]]}],
Spacer@100,
Column[{Row[{Column[{options[[3]]<>")","",""}],ToExpression@text[[4]]}],answers[[3]]}] *)


}]


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


variation2=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,a,b,c,d,e,x,g, vars,text,list,sol,question,all},


text=qRandList[textfghjkl];

aa=RandomChoice@listfghjkl;
g=RandomChoice[{1,2,3}];
Which[g==1,
bb="the total number of employees",
g==2,
bb="the number of employees paid at the higher rate",
g==3,
bb="the number of employees paid at the lower rate"
];

(*{a,b,c,d,e,x}=ToString/@{100,200,300,400,500};*)
{a,b}={2,1};
While[b≤a,{a,b}=RandomPrime[{2,25},2]];
{a,b}=ToString/@{a,b};
x=ToString@RandomInteger[{13,23}];
c=RandomInteger[{25,35}];
d=c-RandomInteger[{6,12}];
{c,d}=ToString/@{c,d};
e=ToString@(ToExpression[x]*(ToExpression[a]*ToExpression[c]+ToExpression[b]*ToExpression[d]));

vars={aa,a,b,c,d,e,x};
Which[g==1,
sol=ToString@(ToExpression[a]*ToExpression[x]+ToExpression[b]*ToExpression[x]),
g==2,
sol=ToString@(ToExpression[a]*ToExpression[x]),
g==3,
sol=ToString@(ToExpression[b]*ToExpression[x])
];

question=StringReplace[text, {"@aa"->aa,"@bb"->bb,"#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}];

(*vars=ToString[{{question,""},{vars}, { sol}},InputForm];*)
all=ToString[{{question,""},{vars},{sol}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->all}],{ vars}, {sol}}

(*{{question," "},{vars}, {sol}}*)

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


solution2=data1<>data2<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,a,b,c,d,e,x, text,list,sol, body={},vars=ertyuiop},



{aa,a,b,c,d,e,x}=vars[[1]];
sol=ToString@(ToExpression[a]*ToExpression[x]+ToExpression[b]*ToExpression[x]);




body={
{ToString[makeTextTable[{{"","# of people","Salary/Person","Total Salary"},{"Higher",ToString[a,TraditionalForm]<>"x","$"<>c,c<>"("<>a<>"x) = "<>ToString[ToExpression[c]*ToExpression[a],TraditionalForm]<>"x"},
{"Lower",b<>"x","$"<>d,d<>"("<>b<>"x) = "<>ToString[ToExpression[d]*ToExpression[b],TraditionalForm]<>"x"},
{"Total","","","$"<>e}}],TraditionalForm],
ToString[ToExpression[c]*ToExpression[a],TraditionalForm]<>"x"<>" + "<>ToString[ToExpression[d]*ToExpression[b],TraditionalForm]<>"x"<>" = "<>e,
ToString[ToExpression[c]*ToExpression[a]+ToExpression[d]*ToExpression[b],TraditionalForm]<>"x"<>" = "<>e,
"x = "<>x,
"\nPeople paid at a higher rate = "<>a<>"("<>x<>") = "<>ToString[ToExpression[a]*ToExpression[x],TraditionalForm],
"People paid at a lower rate = "<>b<>"("<>x<>") = "<>ToString[ToExpression[b]*ToExpression[x],TraditionalForm],
"———————————————————",
"Total number of employees = "<>sol},
{Null ,Null, Null,Null,Null,Null,Null,Null}
};

Panel[Grid[Transpose[body]]]

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


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


body={
{"",
"Set up the unit price number of item and revenue table",
"(Ratio/(a : b))        (Actual/(ax : bx))"},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

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

data="\n"<>"textfghjkl:="<>ToString[{
{"Column[{makeTextTable[{{\"Year \",\"2001\",\"2002\",\"2003\",\"2004\"},{\"Number of students in Managemet\",\"\",#a,#b,\"\"}}]"<>","<>
"ToString[\"fghjkl. The chart above represents the number of students at Ryerson University in Management.\" ]"<>"}]"},


(* a *)
{"Column[{ToString[\" Find the percentage \"<>If[ToExpression[#b]>ToExpression[#a],\"increase\",\"decrease\"]<>\" from 2002 to 2003, round to two decimal places. \",TraditionalForm]}]"},

(*b *)
{"ToString[\" If the number of students increased by #c% from 2003 to 2004, find the number of people in Management in 2004?\",TraditionalForm]"},

(*c *)
{"ToString[\" If the number of students in 2002 is #d% of the number of students in 2001, find the number of students in 2001. Round your answer to nearest student.\",TraditionalForm]"}

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

canvas3="\n"<>ToString[Hold[canvasFunc3[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{
(*ToExpression@question[[1]],*)
ToExpression@text[[1]],

Column[{Row[{options[[1]]<>")",ToExpression@text[[2]]}],Row[{Column[{answers[[1]],""}],"%"}]}] ,
(*makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,2],ToExpression@vars[[2]][[1]][[2]]],*)

Spacer@100,
Column[{Row[{options[[2]]<>")",ToExpression@text[[3]]}],answers[[2]]}],
Spacer@100,
Column[{Row[{options[[3]]<>")",ToExpression@text[[4]]}],answers[[3]]}] 


}]


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





variation3=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,question,x,missing,tmp,m,z},


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

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

(*{a,b}=ToString/@(RandomInteger[{70,90},2]*100);*)

e={1,1};
While[e[[1]]==e[[2]],e=ToString/@(RandomInteger[{70,90},2]*100)];
{a,b}=e;

(* ANNA add the correct formulas *)
(*{c,d,e}=ToString/@{100,100,100};*)
(*e=ToString@100;*)

c=ToString[RandomInteger[{5,40}]];

d=ToString[RandomInteger[{105,140}]];
question=StringReplace[question, {"#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}];

vars={a,b,c,d,e};
(*Anna fix sol *)
sol=ToString[SetPrecision[((ToExpression[b]-ToExpression[a])/ToExpression[a])*100,7],TraditionalForm];

parta={StringReplace[text, {"#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],vars,sol} ;


(* b *)
text=qRandList[textfghjkl[[3]]];


vars={aa,bb,c,d,e};
(*Anna fix sol *)
sol=ToString[IntegerPart[ (1+ ToExpression[c]/100)*ToExpression[b]],TraditionalForm];

partb={StringReplace[text, {"#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],vars,sol} ;


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


vars={aa,bb,c,d,e};
(*Anna fix sol *)
sol=ToString[SetPrecision[ (ToExpression[a]/(ToExpression[d]/100)),10],TraditionalForm];

partc={StringReplace[text, {"#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e}],vars,sol} ;


vars=ToString[{{question, parta[[1]],partb[[1]],partc[[1]]},{ parta[[2]],partb[[2]],partc[[2]]}, { parta[[3]],partb[[3]],partc[[3]]}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ parta[[2]],partb[[2]],partc[[2]]}, { parta[[3]],partb[[3]],partc[[3]]}}


(*{{question,parta[[1]], partb[[1]], partc[[1]]},{parta[[2]], partb[[2]], partc[[2]]}, {parta[[3]], partb[[3]], partc[[3]]}}
*)
(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution3=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,sola,solb,solc, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,index,missing,m,z,a,b,dec},




varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];


body={
{options[[1]]<>":" ,options[[2]]<>":",options[[3]]<>":"},
({{aa,bb,c,d,e}=varsa;
{a,b}=e;
sola=ToString[qTrunc6[SetPrecision[((ToExpression[b]-ToExpression[a])/ToExpression[a])*100,7]],TraditionalForm]
(*ToString[
If[Abs[((ToExpression[b]-ToExpression[a])/ToExpression[a])*100]<10,
SetPrecision[((ToExpression[b]-ToExpression[a])/ToExpression[a])*100,3],
SetPrecision[((ToExpression[b]-ToExpression[a])/ToExpression[a])*100,4]

],TraditionalForm]*);"\n"<>
If[ToExpression[b]>ToExpression[a],ToString["Percentage increase: ",TraditionalForm],ToString["Percentage  decrease: ",TraditionalForm]]<>
"\n"<>If[ToExpression[b]>ToExpression[a]," %↑ = "," %↓ = "]<>ToString[(b - a )/ a,TraditionalForm]<>" × 100% \n"<>
If[ToExpression[b]>ToExpression[a]," %↑ = "," %↓ = "]<>sola<>"%\n",

(*b*)
{aa,bb,c,d,e}=varsb;
solb=ToString[ (1+ ToExpression[c]/100)*ToExpression[b],TraditionalForm];
{a,b}=e;"\n "(*<>sol<>"\n"*)<>
ToString[tv[{
"Method 1",
"F = "<>b<>" + "<>b<>"("<>c<>"%)"<>"\n"<>
"F = "<>b<>" + "<>ToString[(ToExpression[c]/100)*ToExpression[b],TraditionalForm]<>"\n"<>
"F = "<>solb,
"Method 2",
"F = "<>b<>"(100% + "<>c<>"%)"<>"\n"<>
"F = ("<>ToString[SetPrecision[1+(ToExpression[c]/100),3],TraditionalForm]<>")"<>b<>"\n"<>
"F = "<>solb,
"Method 3",
"Triangle Method\n"<>
ToString[tri1[b, "(100% + "<>c<>"%)", "F"],TraditionalForm]<>
"\n                           ⇓"<>
"\nF = "<>b<>"(100% + "<>c<>"%)"<>
"\nF = ("<>ToString[SetPrecision[1+(ToExpression[c]/100),3],TraditionalForm]<>")"<>b<>
"\nF = "<>solb

}],TraditionalForm],

(*c*)
{aa,bb,c,d,e}=varsc;
{a,b}=e;
dec=ToString[SetPrecision[ToExpression[d]/100,3],TraditionalForm];
solc=ToString[qTrunc7[SetPrecision[ (ToExpression[a]/(ToExpression[d]/100)),10]],TraditionalForm];

(*solc=ToString@(qTrunc8[SetPrecision[ (ToExpression[a]/(ToExpression[d]/100)),20],6]);*)
"\n"(*<>sol<>"\n"*)<>
ToString[tv[{
"Method1",
"(Subscript[Students, 2002]) are "<>d<>"% of (Subscript[Students, 2001])\n"<>a<>" is "<>d<>"% of x\n\n"<>ToString[(a/("x")) ,TraditionalForm]<>" = "<>ToString[(d/("100")) ,TraditionalForm]<>
"\n\nx = "<>ToString[((a<>"× 100")/d) ,TraditionalForm]<>
(*"\nx = "<>ToString[SetPrecision[ (ToExpression[a]/(ToExpression[d]/100)),10],TraditionalForm]<>*)
If[FractionalPart[SetPrecision[(ToExpression[a]/(ToExpression[d]/100)),10]]≠ 0,"\nx = "<>ToString[SetPrecision[ (ToExpression[a]/(ToExpression[d]/100)),10],TraditionalForm],""]<>
"\nx = "<>solc,
"Method2",
"Triangle Method\n"<>"(Subscript[Students, 2002]) are "<>d<>"% of (Subscript[Students, 2001])\n"<>a<>" is "<>d<>"% of x\n\n"<>ToString[tri1["whole", d<>"%", a],TraditionalForm]<>"\n⇓"<>
"\nwhole = "<>ToString[a/ToString[SetPrecision[ToExpression[d]/100,3],TraditionalForm],TraditionalForm]<>
If[FractionalPart[SetPrecision[(ToExpression[a]/(ToExpression[d]/100)),10]]≠ 0,"\nwhole = "<>ToString[SetPrecision[ (ToExpression[a]/(ToExpression[d]/100)),10],TraditionalForm],""]<>
"\nwhole = "<>solc

}],TraditionalForm]
})
};

Panel[Grid[Transpose[body]]]

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


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


body={
{options[[1]]<>":\n%↑ or %↓ = \!\(\*FractionBox[\(\(final\)\(\\ \)\(-\)\(\\ \)\(original\)\(\\ \)\), \(original\)]\) × 100%",

options[[2]]<>":\nLet F be the final amount",
"Let P be the original/initial amount",
"%↑ means percent increase",
(*"%↓ means percent decrease\n",*)
"Solve by",
ToString[tv[{
"Method1",
"F = P + P(%↑)    Percent increase"(*\nF = P - P(%↓)    Percent decrease"*),
"Method2",
"F = P(100% + %↑)    Percent increase"(*\nF = P(100% - %↓)    Percent decrease"*),
"Method3",
"Triangle Method\n" <>
ToString[tri1["P", "(100% + %↑)", "F"],TraditionalForm]
}],TraditionalForm]
, 

options[[3]]<>":\n"<>
ToString[tv[{
"Method1",
"Use definition of percents:\n (part/whole) =\!\(\*FractionBox[\(\(%\)\(\\ \)\), \(100\)]\) \n then use cross multiplication:\n whole = \!\(\*FractionBox[\(part\\ ×\\ 100\), \(%\)]\)",
"Method2",
"Triangle Method\n"<>
ToString[tri1["whole", "% ↔ decimal", "part"],TraditionalForm]
}],TraditionalForm]},

{Null ,Null,Null,Null ,Null,Null,Null }
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\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]"<>","<>"\"\""<>"}]",

"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]"<>","<>"\"\""<>"}]"},

(*a*)
{"ToString[\"Find the missing values from table.\",TraditionalForm]",
"ToString[\" 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[\" Determine the equation relating the total cost to the distance given in the form y = mx + b.\"]"<>","<>"ToString[\"Compute m and b. Give an answer in order m b and separate answer using only one space e.g.: 4 2\",TraditionalForm]}]", 
"Column[{ToString[\" Compute the equation relating the total cost to the distance given in the form y = mx + b.\"]"<>","<>"ToString[\"Find m and b. Give an answer in order m b and separate answer using only one space e.g.: 4 2\",TraditionalForm]}]"},

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


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

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

(*f*)
{"ToString[\" If a new model is believed to better describe the relationship between distance 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 ";


canvas4="\n"<>ToString[Hold[canvasFunc4[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{

ToExpression@text[[1]],

PopupView[{makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),{"?","?"},ToExpression@vars[[2]][[1]][[2]]], locs=ToExpression@(vars[[2]][[1]][[2]]);
data=ToExpression@(vars[[2]][[1]][[1]]);
Table[data[[locs[[i]][[1]]]](*[[locs[[i]][[2]]]]*)=Nothing ,{i,1,2}];data=Drop[data,1];ListLinePlot[data,Ticks->None,AxesLabel->{"Distance","Cost"}]}],

Column[{Row[{options[[1]]<>")",ToExpression@text[[3]]}],Row[{"y=",Column[{answers[[3]],""}],"x + ",Column[{answers[[4]],""}]},BaselinePosition->Center]}],
Spacer@100,

options[[2]]<>")"<>ToExpression@text[[2]],

makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,2],ToExpression@vars[[2]][[1]][[2]]],

Spacer@100,
Column[{Row[{options[[3]]<>")",ToExpression@text[[4]]}],answers[[5]]}] ,
Spacer@100,
Column[{Row[{options[[4]]<>")",ToExpression@text[[5]]}],answers[[6]]}],
Spacer@100,
Column[{Row[{options[[5]]<>")",ToExpression@text[[6]]}],answers[[7]]}],
Spacer@100,
Column[{Row[{options[[6]]<>")",ToExpression@text[[7]]}],Row[{Column[{answers[[8]],""}],"km"}]}]

}]


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



variation4=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]
];*)

(* ANN THIS NEEDS TO BE FIXED *)
(*sol= ToString[{ToExpression[c],ToExpression[d]},InputForm];*)
sol={c,d};
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} ;

vars=ToString[{{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]]}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{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 ";


solution4=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]]<>":"},
({

(* 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",

(*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]
],





(* 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, "---- \!\(\*FrameBox[\"1\"]\) "}, {"y = "<>m<>" x"<>toeq, "---- \!\(\*FrameBox[\"2\"]\)"}})}}),TraditionalForm]<>
"\n"<>ToString[tv[{"1",
"Method of Substitution\n"<>
"Substitute \!\(\*FrameBox[\"2\"]\) into \!\(\*FrameBox[\"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 \!\(\*FrameBox[\"1\"]\) and \!\(\*FrameBox[\"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 ";


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


body={
{Column[{
options[[1]]<>": \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",
options[[2]]<>": \nIdentify which variable is given. Solve for the unknown",  
options[[3]]<>": \nExpress slope as a \"rate\".", 
options[[4]]<>": \ny-intercept is parameter b. ", 
options[[5]]<>": \nThink in terms of \"fixed cost\"",
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"}],TraditionalForm]
}]
}
, 
{Null }
};

Panel[Grid[Transpose[body]]]

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

data1="\n"<>"textfghjkl:="<>ToString[{

(* top question*)

{"Column[{fghjkl"<>".ToString[\"An investment of $#a was made #b years ago at a fixed annual rate of interest on a @a. Its maturity value was $#d. Find the fixed rate of annual compound interest on the @a. Round your answer to the nearest percent. \"]"<>","<>"ToString[\"\",TraditionalForm]}]"}



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

data2="listfghjkl:="<>


ToString[{"bond","stock","mutual fund","treasury bill"

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

data=ToString[{data1, data2}, InputForm];


canvas5="\n"<>ToString[Hold[canvasFunc5[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{
(*ToExpression@question[[1]],*)
ToExpression@text[[1]],
Row[{Column[{answers[[1]],""}],"%"}]

}]


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



variation5=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, vars,text,list,sol,sol2,x, parta, partb, partc, partd,question,b2,all},


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

aa=RandomChoice@listfghjkl;
a=ToString@RandomInteger[{40000,60000}];
b=ToString@RandomInteger[{5,15}];
d=ToString@(RandomInteger[{20000,35000}]+ToExpression[a]);

c= ToString@RandomInteger[1000];
vars={a,b,c,d};

question=StringReplace[question, {"@a"->aa,"#a"->a,"#b"->b, "#c"->c,"#d"->d}];

sol2=NSolve[x>0 && ToExpression[d]==ToExpression[a]*(((1+x))^(ToExpression[b])),x,Reals];

If[(x/.sol2[[1]])*100<10,sol=ToString[IntegerPart[ToExpression[ToString[SetPrecision[(x/.sol2[[1]])*100,1]]]],TraditionalForm],sol=ToString[IntegerPart[ToExpression[ToString[SetPrecision[(x/.sol2[[1]])*100,2]]]],TraditionalForm]];

all=ToString[{{question,""},{vars},{sol}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->all}],{vars}, {sol}}
(*{{question," "},{vars}, {sol}}*)



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


solution5=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, text,list,sol,sol2,sol3,x, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,b2,b3},




{a,b,c,d}=vars[[1]];

sol2=NSolve[x>0 && ToExpression[d]==ToExpression[a]*(((1+x))^(ToExpression[b])),x,Reals];
sol=If[(x/.sol2[[1]])*100<10,ToString[IntegerPart[ToExpression[ToString[SetPrecision[(x/.sol2[[1]])*100,1]]]],TraditionalForm],ToString[IntegerPart[ToExpression[ToString[SetPrecision[(x/.sol2[[1]])*100,2]]]],TraditionalForm]];

body={
{
d <>" = "<>a<>ToString["(1 + r)",TraditionalForm],   

ToString[SetPrecision[ToExpression[d]/ToExpression[a],7],TraditionalForm]<>" = "<>ToString["(1 + r)",TraditionalForm], 
ToString[((SetPrecision[ToExpression[d]/ToExpression[a],7])^("("<>ToString[(("1")/b),TraditionalForm]<>")")),TraditionalForm]<>" = "<>ToString["1 + r",TraditionalForm],
If[(x/.sol2[[1]])<0.1,ToString[1+ToExpression[ToString[SetPrecision[(x/.sol2[[1]]),5],TraditionalForm]],TraditionalForm],ToString[1+ToExpression[ToString[(x/.sol2[[1]]),TraditionalForm]],TraditionalForm]]<>" = "<>ToString["1 + r",TraditionalForm],
"r = "<>If[(x/.sol2[[1]])<0.1,ToString[SetPrecision[(x/.sol2[[1]]),5],TraditionalForm],ToString[(x/.sol2[[1]]),TraditionalForm]],
"r = "<>sol<>"%"

},
{Null ,Null, Null,Null,Null,Null}
};

Panel[Grid[Transpose[body]]]

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


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


body={ 
{"A = final amount/future value\nP = Present value\nr = interest rate(as a decimal)\nn = time\n","A = P(1 + r)^n"},
{Null ,Null}
};

Panel[Grid[Transpose[body]]]

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

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<>".ToString[\"Simple interest is used to calculate the amount of depreciation on a @a that was purchased for $#a on @b 1. Assuming that the annual rate of depreciation on this @a is #c%, determine the amount of depreciation on the @a for the remainder of the year. (Note that #d days have passed from January 1 to end of @b.)\"]",
"fghjkl"<>".ToString[\"On @b 1 a @a was purchased. Simple interest is used to calculate the amount of depreciation. Determine the amount of depreciation on the @a for the remainder of the year, assuming that the annual rate of depreciation on this @a is #c% , while #d days have passed from January 1 to end of @b.\"]"},InputForm]<>";\n "; 

(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>

(*{specific name, abbriviated name, name of the type of thing, location name}*)

ToString[{"car","motorcycle", "boat", "SUV"


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

data=ToString[{data1, data2}, InputForm];

canvas6="\n"<>ToString[Hold[canvasFunc6[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{
(*ToExpression@question[[1]],*)
ToExpression@text[[1]],

Row[{"$",Column[{answers[[1]],""}]}] (*,
(*makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,2],ToExpression@vars[[2]][[1]][[2]]],*)

Spacer@100,
Column[{Row[{Column[{options[[2]]<>")","",""}],ToExpression@text[[3]]}],answers[[2]]}],
Spacer@100,
Column[{Row[{Column[{options[[3]]<>")","",""}],ToExpression@text[[4]]}],answers[[3]]}] *)


}]


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


variation6=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{a,b,c,d,i,f,g,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, vars,text,list,sol,question,all},


aa=qRandList[listfghjkl];
text=qRandList[textfghjkl];

{a,b, c}=ToString/@{RandomInteger[{2,5}]*10000, RandomInteger[{3,7}], RandomInteger[{15,25}]};
d = ToString[30*ToExpression[b]]; 
sol=ToString[N[ToExpression[a]*(ToExpression[c]/100)*((365-30*ToExpression[b])/365)]]; 

bb=qMonths[[ToExpression[b]]];

vars={aa,bb,a,b,c,d, sol};

question=StringReplace[text, { "@a"->aa,"@b"->bb,"#a"->a,"#b"->b,"#c"->c,"#d"->d}]; 
all=ToString[{{question,""},{vars},{sol}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->all}],{ vars}, {sol}}

(*{{question," "},{vars}, {sol}}  *)
]],InputForm]<>"\n ";




solution6=data1<>data2<>ToString[Hold[Module[{a,b,c,f,g,i,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, text,list,sol, body={},vars=ertyuiop,d},




{aa,bb,a,b,c,d, sol}=vars[[1]]; 


body={
{"", 
"I = "<>ToString[ToExpression[a],TraditionalForm]<>"("<>ToString[N[(ToExpression[c]/100)],TraditionalForm] <>")"<>"\!\(\*
StyleBox[\"(\",\nFontSize->16]\)"<>ToString[(365-30*ToExpression[b])/ToString["365",TraditionalForm],TraditionalForm]<>"\!\(\*
StyleBox[\")\",\nFontSize->16]\)",
"I = "<>ToString[qTrunc6[ToExpression[sol]],TraditionalForm]},   
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

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


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


body={
{"", 
"I= P r t", 
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

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

data1="\n"<>"textfghjkl:="<>ToString[
{"Column[{ToString[\"fghjkl. \"<>Capitalize[IntegerName[ToExpression[#a]]]<>\" chocolate bars and \"<>IntegerName[ToExpression[#b]]<>\" ice-cream cones cost $#c. \"<>Capitalize[IntegerName[ToExpression[#d]]]<>\" chocolate bars and \"<>IntegerName[ToExpression[#e]]<>\" ice-cream cost $#f. Find the cost of @a.\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},InputForm]<>";\n ";

data2="listfghjkl:="<>


ToString[{"a chocolate bar","an ice-cream cone"

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

data=ToString[{data1, data2}, InputForm];


canvas7="\n"<>ToString[Hold[canvasFunc7[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{
(*ToExpression@question[[1]],*)
ToExpression@text[[1]],

Row[{"$",Column[{answers[[1]],""}]}] (*,
(*makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,2],ToExpression@vars[[2]][[1]][[2]]],*)

Spacer@100,
Column[{Row[{Column[{options[[2]]<>")","",""}],ToExpression@text[[3]]}],answers[[2]]}],
Spacer@100,
Column[{Row[{Column[{options[[3]]<>")","",""}],ToExpression@text[[4]]}],answers[[3]]}] *)


}]


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




variation7=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,a,b,d,c,e,f,p,x,y, vars,text,list,sol,question,all},


text=qRandList[textfghjkl];

aa=RandomChoice[listfghjkl];

(*{a,b,d,e}=ToString/@RandomInteger[{2,10},4];
{c,f}=ToString/@RandomReal[{1,4},2];*)
x=ToString@(RandomInteger[{50,80}]*0.01);
y=ToString@(RandomInteger[{70,99}]*0.01);
{a,b}=RandomInteger[{2,7},2];
{d,e}={a,b};
While[{d,e}=={a,b},{d,e}=RandomInteger[{2,7},2]];
{a,b,d,e}=ToString/@{a,b,d,e};
c=ToString@(ToExpression[a]*ToExpression[x]+ToExpression[b]*ToExpression[y]);
f=ToString@(ToExpression[d]*ToExpression[x]+ToExpression[e]*ToExpression[y]);

vars={ a,b,c,d,e,f,x,y,aa};
sol=x;
If[aa==="a chocolate bar",
sol=x,
sol=y];



question=StringReplace[text, {"@a"->aa,"#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e,"#f"->f}];
all=ToString[{{question,""},{vars},{sol}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->all}],{ vars}, {sol}}

(*{{question," "},{vars}, {sol}}*)

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


solution7=data1<>data2<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,a,b,c,d,e,f,p,x,y,ad,ae,af,da,db,dc,text,list,sol, body={},vars=ertyuiop},



{a,b,c,d,e,f,x,y,aa}=vars[[1]];

sol=ToString[{ToExpression[x],ToExpression[y]},TraditionalForm];

da=ad=ToString[ToExpression[d]*ToExpression[a]];
db=ToString[ToExpression[d]*ToExpression[b]];
dc=ToString[ToExpression[d]*ToExpression[c]];
ae=ToString[ToExpression[e]*ToExpression[a]];
af=ToString[ToExpression[f]*ToExpression[a]];

body={
{
"Let x represent cost per chocolate bars",
"Let y represent cost per ice cream cone",
ToString[({{\[Piecewise], ({{a<>" x + "<>b<>" y = "<>c, "····· \!\(\*FrameBox[\"1\"]\)"}, {d<>" x + "<>e<>" y = "<>f, "····· \!\(\*FrameBox[\"2\"]\)"}})}}),TraditionalForm],
tv[{"Method 1",
"Method of Substitution\n"<>ToString[({{\[Piecewise], ({{"x = "<>ToString[(("1")/a),TraditionalForm]<>"(-"<>b<>" y + "<>c<>")", "····· \!\(\*FrameBox[\"1\"]\)"}, {d<>" x + "<>e<>" y = "<>f, "····· \!\(\*FrameBox[\"2\"]\)"}})}}),TraditionalForm]<>"\nSubstitute \!\(\*FrameBox[\"1\"]\) into \!\(\*FrameBox[\"2\"]\)\n"<>
d<>"["<>ToString[(("1")/a),TraditionalForm]<>"(-"<>b<>" y + "<>c<>")] + "<>e<>" y = "<>f<>"····· × "<>a<>"\n"<>
d<>"(-"<>b<>" y + "<>c<>") + "<>ToString[ToExpression[e]*ToExpression[a],TraditionalForm]<>" y = "<>ToString[ToExpression[f]*ToExpression[a],TraditionalForm]<>"\n"<>
"-"<>ToString[ToExpression[d]*ToExpression[b],TraditionalForm]<>" y + "<>ToString[ToExpression[d]*ToExpression[c],TraditionalForm]<>" + "<>ToString[ToExpression[e]*ToExpression[a],TraditionalForm]<>" y = "<>ToString[ToExpression[f]*ToExpression[a],TraditionalForm]<>"\n"<>
ToString[ToExpression[e]*ToExpression[a],TraditionalForm]<>" y - "<>ToString[ToExpression[d]*ToExpression[b],TraditionalForm]<>" y = "<>ToString[ToExpression[f]*ToExpression[a],TraditionalForm]<>" - "<>ToString[ToExpression[d]*ToExpression[c],TraditionalForm]<>"\n"<>ToString[ToExpression[e]*ToExpression[a]-ToExpression[d]*ToExpression[b],TraditionalForm]<>" y = "<>ToString[ToExpression[f]*ToExpression[a]-ToExpression[d]*ToExpression[c],TraditionalForm]<>
"\ny = "<>y<>"\n\n"<>
"x = "<>ToString[(("1")/a),TraditionalForm]<>"((-"<>b<>")("<>y<>") + "<>c<>")\n"<>
"x = "<>ToString[(("1")/a),TraditionalForm]<>"(-"<>ToString[ToExpression[b]*ToExpression[y],TraditionalForm]<>" + "<>c<>")\n"<>
"x = "<>ToString[(("1")/a),TraditionalForm]<>"("<>ToString[-ToExpression[b]*ToExpression[y]+ ToExpression[c],TraditionalForm]<>")\n"<>
"x = "<>x
,
"Method 2",
"Method of Elimination\n"<>ToString[({{\[Piecewise], ({{a<>" x + "<>b<>" y = "<>c, "····· \!\(\*FrameBox[\"1\"]\) ×"<>d}, {d<>" x + "<>e<>" y = "<>f, "····· \!\(\*FrameBox[\"2\"]\) ×"<>a}})}}),TraditionalForm]<>"\n"<>ToString[({{\[Piecewise], ({{da<>" x + "<>db<>" y = "<>dc, "····· \!\(\*FrameBox[\"1\"]\) "}, {ad<>" x + "<>ae<>" y = "<>af, "····· \!\(\*FrameBox[\"2\"]\) "}})}}),TraditionalForm]<>"\nEliminate x by\n Substracting \!\(\*FrameBox[\"1\"]\) and \!\(\*FrameBox[\"2\"]\)\n"<>
db<>" y - "<>ae<>" y = "<>dc<>" - "<>af<>"\n"<>
ToString[ToExpression[db] - ToExpression[ae],TraditionalForm]<>" y = "<>ToString[ToExpression[dc]-ToExpression[af],TraditionalForm]<>"\n"<>
"y = "<>y<>"\n\n"<>
a<>" x + "<>b<>"("<>y<>") = "<>c<>"\n"<>
a<>" x + "<>ToString[ToExpression[b]*ToExpression[y],TraditionalForm]<>" = "<>c<>"\n"<>
a<>" x = "<>c<>" - "<>ToString[ToExpression[b]*ToExpression[y],TraditionalForm]<>"\n"<>
a<>" x = "<>ToString[ToExpression[c]-ToExpression[b]*ToExpression[y],TraditionalForm]<>"\n"<>
"x = "<>x
,
"Method 3",
"Alternative Method of Elimination\n"<>

ToString[({{\[Piecewise], ({{a<>" x + "<>b<>" y = "<>c, "····· \!\(\*FrameBox[\"1\"]\) ×"<>d}, {d<>" x + "<>e<>" y = "<>f, "····· \!\(\*FrameBox[\"2\"]\) ×"<>a}})}}),TraditionalForm]<>"\n"<>ToString[({{\[Piecewise], ({{da<>" x + "<>db<>" y = "<>dc, "····· \!\(\*FrameBox[\"1\"]\) "}, {ad<>" x + "<>ae<>" y = "<>af, "····· \!\(\*FrameBox[\"2\"]\) "}})}}),TraditionalForm]<>"\n"<>
"Isolate "<>da<>" x\n"<>

ToString[({{\[Piecewise], ({{da<>" x = "<>dc<>" - "<>db<>" y", "····· \!\(\*FrameBox[\"1\"]\) "}, {ad<>" x = "<>af<>" - "<>ae<>" y", "····· \!\(\*FrameBox[\"2\"]\) "}})}}),TraditionalForm]<>"\n"<>
dc<>" - "<>db<>" y = "<>af<>" - "<>ae<>" y"<>"\n"<>
ae<>" y"<>" - "<>db<>" y = "<>af<>" - "<>dc<>"\n"<>
ToString[ToExpression[ae] - ToExpression[db],TraditionalForm]<>" y = "<>ToString[ToExpression[af] - ToExpression[dc],TraditionalForm]<>"\n"<>" y = "<>y<>"\n\n"<>
a<>" x + "<>b<>"("<>y<>") = "<>c<>"\n"<>
a<>" x + "<>ToString[ToExpression[b]*ToExpression[y],TraditionalForm]<>" = "<>c<>"\n"<>
a<>" x = "<>c<>" - "<>ToString[ToExpression[b]*ToExpression[y],TraditionalForm]<>"\n"<>
a<>" x = "<>ToString[ToExpression[c]-ToExpression[b]*ToExpression[y],TraditionalForm]<>"\n"<>
"x = "<>x
}],
"Answer:"<>
If[aa==="a chocolate bar",
x,
y]
},
{Null ,Null,Null,Null,Null}
};

Panel[Grid[Transpose[body]]]

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


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


body={
{"Think System of Equations.",
"Solved by: ",
ToString[tv[{"Method 1","Method of Substitustion","Method 2","Method of Elimination","Method 3","Alternative Method of Elimination"}],TraditionalForm]},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

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

data1="\n"<>"textfghjkl:="<>ToString[
{"Column[{ToString[\"fghjkl. The formula for the revenue of a certains businesss is given as:\",TraditionalForm]"<>","<>"ToString[ToString[\"@a = \",TraditionalForm]<>ToString[ToString[@b*Sqrt[@c],TraditionalForm]/\"#d\",TraditionalForm],TraditionalForm]"<>","<>
"ToString[\", where @a represents the revenue in millions of dollars in year number @c and @b represents the amount of cash available in millions of dollars when the company was originally purchased. If @a=#a and @b=#b, solve for @c.\",TraditionalForm]"<>"}]"},InputForm]<>";\n ";

data2="listfghjkl:="<>


ToString[{""

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

data=ToString[{data1, data2}, InputForm];



canvas8="\n"<>ToString[Hold[canvasFunc8[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{
(*ToExpression@question[[1]],*)
ToExpression@text[[1]],

Column[{"",answers[[1]]}] 


}]


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



variation8=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,a,b,d,c,p,x, vars,text,list,sol,question,all},


text=qRandList[textfghjkl];

x=RandomInteger[{5,9}];
c=ToString@(x*x);
d=ToString@RandomInteger[{2,6}];
b=ToString@(ToExpression[d]*RandomInteger[{4,9}]);
a=ToString@((ToExpression[b]*x)/ToExpression[d]);

{aa,bb,cc,dd}=nLetters[{"a","y"},4]/.{"l"->"L","o"->"z"}; 
x=ToString[x];
(*{a,b,c,d}=ToString/@{RandomInteger[{4,10}],RandomInteger[{4,10}],RandomInteger[{4,10}],RandomInteger[{2,3}]};*)
vars={aa,bb,cc,dd, a,b,c,d,x};
sol=c;



question=StringReplace[text, {"@a"->aa,"@b"->bb,"@c"->cc,"@d"->dd,"#a"->a,"#b"->b,"#c"->c,"#d"->d}];

all=ToString[{{question,""},{vars},{sol}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->all}],{ vars}, {sol}}

(*{{question," "},{vars}, {sol}}*)

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


solution8=data1<>data2<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,a,b,c,d,p,x, text,list,sol, body={},vars=ertyuiop},



{aa,bb,cc,dd, a,b,c,d,x}=vars[[1]];





body={
{
a<>" = "<>ToString[((b<>ToString[(Sqrt[cc]),TraditionalForm])/d),TraditionalForm],
ToString[ToExpression[a]*ToExpression[d],TraditionalForm]<>" = "<>b<>ToString[(Sqrt[cc]),TraditionalForm],
x<>" = "<>ToString[(Sqrt[cc]),TraditionalForm],
ToString[((ToString[x,TraditionalForm])^2),TraditionalForm]<>" = "<>cc,
cc<>" = "<>c
},
{Null ,Null,Null,Null,Null}
};

Panel[Grid[Transpose[body]]]

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


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


body={
{"Identify which variables are given and which is the unknown.",
"Use cross multiplication (a/b) = (x/c) ⟹ x = (ac/b)"},
{Null ,Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";
data="\n"<>"textfghjkl:="<>ToString[{


(* top question*)
{"Column[{ToString[\"fghjkl. 
● #f% of all TRSM students spend #b hours or more per day on FACEBOOK.
● #g% of all students who spend #b hours per day or more on FACEBOOK have GPA's below #d.
● At TRSM, #h% of all students have GPA's below #d.\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},

(*a*)
{"ToString[\" Use the information shown above to fill in the chart below:\"]"},


(*b*)
{"Column[{ToString[\" Determine the probability that a student achieves a GPA of #d or higher, given that they use FACEBOOK for #b hours or more per day.\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},

(*c*)
{"Column[{ToString[\" Determine the probability that a student is on FACEBOOK less than #b h given that they have a GPA of #d or more.\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"}
},InputForm]<>";\n ";



canvas9="\n"<>ToString[Hold[canvasFunc9[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars[[1]];
Column[{
(*ToExpression@question[[1]],*)
ToExpression@text[[1]],
Column[{Row[{options[[1]]<>")",ToExpression@text[[2]]}]}] ,
makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,9],ToExpression@vars[[2]][[1]][[2]]],
Spacer@100,
Column[{Row[{Column[{options[[2]]<>")",""}],ToExpression@text[[3]]}],answers[[10]]}],
Spacer@100,
Column[{Row[{Column[{options[[3]]<>")",""}],ToExpression@text[[4]]}],answers[[11]]}] 


}]


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



variation9=data<>ToString[Hold[Module[{a,b,c,d,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, vars,text,list,sol,solnew, parta, partb, partc, partd,question,b2,table,vec}, 


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

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


(*a=all Regular Exercise, b=No Regular Exercise, c= #female regular, d=#male regular*)

vec = {70,10,50};
While[(vec[[1]]-vec[[2]]*0.01*vec[[1]])≥ (100-vec[[3]])(* && vec[[1]]>=vec[[3]]*)(*&& vec[[3]]<vec[[2]]*0.01*vec[[1]]*),
vec[[1]]=RandomInteger[{1,7}]*10;
vec[[2]]=RandomInteger[{1,7}]*10;
vec[[3]] = vec[[1]]+ RandomInteger[{1,3}]*10
];
{f,g,h}=ToString/@vec;

(*{f,g,h}=ToString/@{RandomInteger[{1,7}]*10,RandomInteger[{1,7}]*10,RandomInteger[{1,5}]*10};*)
{a,b,c,d}=ToString/@{RandomInteger[{10,60}],RandomInteger[{1,10}],RandomInteger[{10,60}],RandomInteger[{2,3}]};


(*"\"-\""*)
table={
{"\"All in %\"",ToString[" < "<>b<>"h\n"<>"FACEBOOK",TraditionalForm],ToString[" ⩾ "<>b<>"h\n"<>"FACEBOOK",TraditionalForm],"\"Total\""},
{ToString["GPA < "<>d,TraditionalForm],"\"-\"","\"-\"","\"-\""},
{ToString["GPA ≥ "<>d,TraditionalForm],"\"-\"","\"-\"","\"-\""},
{"Total","\"-\"","\"-\"","100"}};




question=StringReplace[question, {"#a"->a,"#b"->b, "#c"->c,"#d"->d,"#f"->f,"#g"->g,"#h"->h}];

(*{{2,2},{2,3},{2,4},{3,2},{3,3},{3,4},{4,2},{4,3},{4,4}} are the entries where the answers are supposed to be in the table *)
sol={(*first row*)
IntegerPart[ToExpression[h] - IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))]],
IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))],
IntegerPart[ToExpression[h]],

(*second row*)
IntegerPart[IntegerPart[(100 - ToExpression[h] )]- IntegerPart[(ToExpression[f]-((ToExpression[g]*0.01)*(ToExpression[f])))]],
IntegerPart[ToExpression[f] -IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))]],
IntegerPart[100 - ToExpression[h]],

(*third row*)
IntegerPart[100 - ToExpression[f]],
IntegerPart[ToExpression[f]],
100}
;
vars={table,ToString@{{2,2},{2,3},{2,4},{3,2},{3,3},{3,4},{4,2},{4,3},{4,4}},a,b,c,d,f,g,h};
parta={text,vars,sol} ;


(* part b*)
text=qRandList[textfghjkl[[3]]];

(*sol=SetPrecision[((ToExpression[f]*0.01 - ToExpression[g]*0.01*ToExpression[f]*0.01)/(ToExpression[f]*0.01)),10]; *)

sol=ToString[
{ToString[SetPrecision[(ToExpression[f] - ToExpression[g]*0.01*ToExpression[f])/ToExpression[f],10],TraditionalForm],
ToString[IntegerPart[ToExpression[f]*(1- ToExpression[g]*0.01)]/IntegerPart[ToExpression[f]],TraditionalForm]
},TraditionalForm];
solnew=ToExpression[sol,TraditionalForm];

vars={a,b, c,f,g,h,ToString@{sol}};

partb={StringReplace[text, {"#a"->a,"#b"->b, "#c"->c,"#d"->d}],vars,sol} ;



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

sol=ToString[
{ToString[SetPrecision[N[(1 - ToExpression[h]*0.01 )- (ToExpression[f]*0.01 -((ToExpression[g]*0.01)*(ToExpression[f]*0.01)))]/N[1 - ToExpression[h]*0.01],10],TraditionalForm],
ToString[IntegerPart[N[(100 - ToExpression[h] )- (ToExpression[f]-((ToExpression[g]*0.01)*(ToExpression[f])))]]/IntegerPart[100 - ToExpression[h]],TraditionalForm]
},TraditionalForm]; (*4*)
solnew=ToExpression[sol,TraditionalForm];
vars={a,b, c,f,g,h,ToString@{sol}};

partc={StringReplace[text, {"#a"->a,"#b"->b, "#c"->c,"#d"->d}],vars,sol} ;




vars=ToString[{{question, parta[[1]],partb[[1]],partc[[1]]},{ parta[[2]],partb[[2]],partc[[2]]}, { parta[[3]],partb[[3]],partc[[3]]}},InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ parta[[2]],partb[[2]],partc[[2]]}, { parta[[3]],partb[[3]],partc[[3]]}}

(*{{question,parta[[1]], partb[[1]],partc[[1]]},{parta[[2]], partb[[2]],partc[[2]]}, parta[[3]]~Join~{ partb[[3]],partc[[3]]}}*)(*KLUDGE: part 3 all wrong*)



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


solution9=data<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,b2,b3,table,locs},



varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];


{table,locs,a,b,c,d,f,g,h}=varsa;



body={
{options[[1]]<>":" ,
"Based on the percents from the task:",
makeTextTable[{{"All in %",ToString[" < "<>b<>"h\n"<>"FACEBOOK",TraditionalForm],ToString[" ⩾ "<>b<>"h\n"<>"FACEBOOK",TraditionalForm],"Total"}, 
{ToString["GPA < "<>d,TraditionalForm],
"-",
ToString[ToString[(N[ToExpression[g]*0.01]),TraditionalForm]<>"\[Cross]"<> f<>"="<>ToString[IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))],TraditionalForm],TraditionalForm],
ToString[ToString[(N[ToExpression[h]*0.01]),TraditionalForm]<>"\[Cross]100 = "<>h,TraditionalForm]},

{ToString["GPA ⩾ "<>d,TraditionalForm],
"-",
"-",
"-"},

{"Total",
"-",
ToString[ToString[(N[ToExpression[f]*0.01]),TraditionalForm]<>"\[Cross]100 = "<>f,TraditionalForm],
"100"}}],


"\nNext part of table full fill using substraction:",

makeTextTable[{{"All in %",ToString[" < "<>b<>"h\n"<>"FACEBOOK",TraditionalForm],ToString[" ⩾ "<>b<>"h\n"<>"FACEBOOK",TraditionalForm],"Total"},

{ToString["GPA < "<>d,TraditionalForm],
ToString[(IntegerPart[ToExpression[h]]),TraditionalForm]<>" - "<>ToString[IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))],TraditionalForm]<>" = "<>ToString[IntegerPart[ToExpression[h]- ((ToExpression[g]*0.01)*(ToExpression[f]))],TraditionalForm],
Style[ToString[IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))],TraditionalForm],Blue],
Style[ToString[(IntegerPart[ToExpression[h]]),TraditionalForm],Blue]},


{ToString["GPA ⩾ "<>d,TraditionalForm],
ToString[IntegerPart[100 - ToExpression[h]],TraditionalForm]<>" - "<>ToString[IntegerPart[ToExpression[f] -IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))]],TraditionalForm]<>" = "<> ToString[IntegerPart[IntegerPart[(100 - ToExpression[h] )]- IntegerPart[(ToExpression[f] -IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))])]],TraditionalForm],
ToString[f<>"-"<>ToString[IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))],TraditionalForm]<>"="<>ToString[IntegerPart[ToExpression[f] -IntegerPart[((ToExpression[g]*0.01)*(ToExpression[f]))]],TraditionalForm],TraditionalForm],
ToString["100-"<>h<>"="<>ToString[IntegerPart[100 - ToExpression[h]],TraditionalForm],TraditionalForm]},


{"Total",ToString["100-"<>f<>"="<>ToString[IntegerPart[100 - ToExpression[f]],TraditionalForm],TraditionalForm],Style[f,Blue],
Style["100",Blue]}}],
"",
(*b*)
{a,b, c,f,g,h,sol}=varsb;options[[2]]<>":\n"<>ToString["P( GPA ≥ "<>d,TraditionalForm]<>" | FB ⩾ "<>b<>" ) = "<>ToString[ToString[IntegerPart[ToExpression[f] - ToExpression[g]*0.01*ToExpression[f]],TraditionalForm]/ToString[ToExpression[f],TraditionalForm],TraditionalForm]<>" = "<>

If[Denominator[((IntegerPart[ToExpression[f]*(1- ToExpression[g]*0.01)])/(IntegerPart[ToExpression[f]]))]==ToExpression[f],"",
ToString[Simplify[IntegerPart[ToExpression[f]*(1- ToExpression[g]*0.01)]/IntegerPart[ToExpression[f]]],TraditionalForm]<>" = "]<>
ToString[qTrunc6(*SetPrecision*)[N[((ToExpression[f] - ToExpression[g]*0.01*ToExpression[f])/(ToExpression[f]))](*,1*)],TraditionalForm]<>"\n",

(*c*)
{a,b, c,f,g,h,sol}=varsc;options[[3]]<>":\n"<>ToString["P( FB < "<>b,TraditionalForm]<>" | GPA ⩾ "<>d<>" ) = "<>ToString[ToString[IntegerPart[(100 - ToExpression[h] )- (ToExpression[f]-((ToExpression[g]*0.01)*(ToExpression[f])))],TraditionalForm]/ToString[100 - ToExpression[h],TraditionalForm],TraditionalForm]<>" = "<>

If[Denominator[IntegerPart[N[(100 - ToExpression[h] )- (ToExpression[f]-((ToExpression[g]*0.01)*(ToExpression[f])))]]/IntegerPart[100 - ToExpression[h]]]==(100 - ToExpression[h]),"",
ToString[IntegerPart[N[(100 - ToExpression[h] )- (ToExpression[f]-((ToExpression[g]*0.01)*(ToExpression[f])))]]/IntegerPart[100 - ToExpression[h]],TraditionalForm]<>" = "]<>


ToString[qTrunc6(*SetPrecision*)[N[N[(100 - ToExpression[h] )- (ToExpression[f] -((ToExpression[g]*0.01)*(ToExpression[f])))]/N[100 - ToExpression[h]]](*,2*)],TraditionalForm]<>"\n"},

{Null,Null,Null,Null ,Null, Null,Null,Null}
};

Panel[Grid[Transpose[body]]]

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


hint9=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]]<>": \n The first and the third clues are standalone cluses. \nThe second clue has something to do with the first clue given.\n", 
options[[2]]<>": \n P( an event happening ) = "<>ToString[("n( event )")/"n( all possibilities with no restrictions )",TraditionalForm]<>"\n", 
options[[3]]<>": \n Think \"Conditional Probability\" \n P(A|B) = "<>ToString[("P(A ⋂ B)")/"P(B)",TraditionalForm]
}],TraditionalForm]
}, 
{Null (*,Null, Null*)}
};

Panel[Grid[Transpose[body]]]

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

FUNCTION

qCanvas=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,canvas,canvas0,firstCanvas=True},Panel[Column[{If[diag00==0||diag00==2,Panel[Row[{OpenerView[{Button["Try Again",(*AppendTo[level1[[3]],prev];*)first=ConstantArray[True,mult0];
level1=again;firstCanvas=True;
{canvas,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"canvasZ"->canvas0,"fghjkl"->ToString[pn]}]]];

Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;
myEnabled[[i]]=True,{i,1,mult0}];],""}],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[{(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]][(Flatten@sol)[[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]][(Flatten@sol)[[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,"ERROR: WRONG ANSWER MATCHING\n"<>ToString/@sol]]]


,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,mult0}]);(*Dynamic@(If[firstCanvas==True,ReleaseHold[ToExpression[StringReplace[canvas,{"mmm"->"canvasFUNC"<>ToString[pn]}]]];
firstCanvas=False];(ToExpression@("canvasFUNC"<>ToString[pn]))@answers)}] (*ReleaseHold needs to be controlled or loops 20 times a second*)*)

(*Dynamic@(If[firstCanvas==True,firstCanvas=False;ReleaseHold[ToExpression[ReleaseHold[ToExpression[canvas]]]],"hi"]),*)

Dynamic@( (*this has to be here to vary canvas varittions*)
If[firstCanvas==True,ReleaseHold[ToExpression[ReleaseHold[ToExpression[canvas]]]];firstCanvas=False];ToExpression["canvasFunc"<>ToString[pn]]@{answers,options})
(*Dynamic@ReleaseHold[ToExpression[canvas]]*)

}] (*ReleaseHold needs to be controlled or loops 20 times a second*)
}]],



(*{{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;diag0=diag00;
io=ToExpression[IO00];
SetOptions[EvaluationNotebook[],DynamicEvaluationTimeout->100];

SetOptions[EvaluationNotebook[],PrivateNotebookOptions->{"PluginToolbarEnabled"->False},DockedCells->Cell[BoxData[ToBoxes[Row[{Column[{Image[logo,ImageSize->200],"Sept 2015"},ItemSize->{20,Automatic}],PopupMenu[Dynamic[CurrentValue[EvaluationNotebook[],"Magnification"]],Range[0.5,3,0.5]]},Spacer[5]]]],"DockedCell"]];
(*SetOptions[EvaluationNotebook[],DockedCells->Cell[BoxData[ToBoxes[PopupMenu[Dynamic[CurrentValue[EvaluationNotebook[],"Magnification"]],Range[0.5,3,0.5]]]],"DockedCell"]];*)
(*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]],CharacterRange["A","Z"][[1;;mult]]}],options={" "}];
{again,variation,hint,solution,canvas0}=proc;
again=ToExpression[again];
level1=again;
{canvas,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"canvasZ"->canvas0,"fghjkl"->ToString[pn]}]]];
firstCanvas=True;)]],InputForm]<>"\n";

CONFIGURATIONS

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

proc2=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation2,hint2,solution2,canvas2},InputForm]<>";\n";

proc3=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation3,hint3,solution3,canvas3},InputForm]<>";\n";

proc4=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation4,hint4,solution4,canvas4},InputForm]<>";\n";

proc5=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation5,hint5,solution5,canvas5},InputForm]<>";\n";

proc6=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation6,hint6,solution6,canvas6},InputForm]<>";\n";

proc7=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation7,hint7,solution7,canvas7},InputForm]<>";\n";

proc8=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation8,hint8,solution8,canvas8},InputForm]<>";\n";

proc9=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation9,hint9,solution9,canvas9},InputForm]<>";\n";



ToExpression@libGUI;
ToExpression@libIO;
ToExpression@libML;
panelsMIX={ StringReplace[qCanvas,{"pn0"->ToString[1],"proc0"->proc1,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO,errNO,errNO,errNO}","inputsize0"->"{5,5,5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"4","diag00"->"0","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvas,{"pn0"->ToString[2],"proc0"->proc2,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{errNO}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"0","IO00"->"qClick","logo"->ToString[,InputForm]}],


StringReplace[qCanvas,{"pn0"->ToString[3],"proc0"->proc3,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libGraphics<>"\n"<>libMISC<>"\n"<>libGUI),"err0"->"{err2,errNO,err3}","inputsize0"->"{8,8,8}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"3","diag00"->"0","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvas,{"pn0"->ToString[4],"proc0"->proc4,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC<>"\n"<>libML<>"\n"),"err0"->"{errNO,errNO,errNO,errNO,err5,errNO,err6,errNO}","inputsize0"->"{5,5,5,5,30,5,30,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"8","diag00"->"2","IO00"->"qClick","logo"->ToString[,InputForm]}],


StringReplace[qCanvas,{"pn0"->ToString[5],"proc0"->proc5,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC<>"\n"<>libGUI),"err0"->"{errNO}", "inputsize0"->"{8}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"0","IO00"->"qClick","logo"->ToString[,InputForm]}],


StringReplace[qCanvas,{"pn0"->ToString[6],"proc0"->proc6,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{err2}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick","logo"->ToString[,InputForm]}],


StringReplace[qCanvas,{"pn0"->ToString[7],"proc0"->proc7,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{err2}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"0","IO00"->"qClick","logo"->ToString[,InputForm]}],


StringReplace[qCanvas,{"pn0"->ToString[8],"proc0"->proc8,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"0","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvas,{"pn0"->ToString[9],"proc0"->proc9,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC<>"\n"<>libML),"err0"->"{errNO,errNO,errNO,errNO,errNO,errNO,errNO,errNO,errNO,errMIX2,errMIX2}","inputsize0"->"{5,5,5,5,5,5,5,5,5,5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"11",
"diag00"->"0","IO00"->"qClick","logo"->ToString[,InputForm]}]
};

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

COMPILATION

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