libLIST=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/HW2/libLIST.m"]<>"\n";
libNAMES=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/HW2/libNAMES.m"]<>"\n";
libIO=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/HW2/libIO.m"]<>"\n";
libERR=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/HW2/libERR.m"]<>"\n";
libGUI=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/HW2/libGUI.m"]<>"\n";
libML=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/HW2/libML.m"]<>"\n";
libMISC=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/HW2/libMISC.m"]<>"\n";
libGraphics=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/HW2/libGraphics.m"]<>"\n";

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

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

"0"->{"Column[{ToString[\"fghjkl. For each Set below choose the valid statement:\",TraditionalForm]"<>","<>"ToString[\"Select by pulling down the menu\"]"<>"}]","Column[{ToString[\"fghjkl. Indicate the valid statemet for each Set:\",TraditionalForm]"<>","<>"ToString[\"Select by pulling down the menu \"]"<>"}]"},



"1"-><|
(*AND*)
"1.1"->{"Column[{ToString[\" Given the Set:\"]"<>"}]"}

|>(*,

"2"-><|
(* 2.1 is always False*)
"2.1"->{"Column[{ToString[\" @a is @c if and olny if @b is @c:\"]"<>"}]"},

(*2.2 is always True *)
"2.2"->{"Column[{ToString[\"All people are @c :\"]"<>"}]"},

"2.3"->{"Column[{ToString[\"Some people are @c:\"]"<>"}]"}

|>*)


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


data2="listfghjkl:="<>


ToString[
<|

"1.1"->{

Hold@<|
"set"->{ToString@ToUpperCase[RandomSample[DictionaryLookup[],1][[1]]],ToString@ToUpperCase[RandomSample[DictionaryLookup[],1][[1]]],ToString@ToUpperCase[RandomSample[DictionaryLookup[],2]],ToString@ToUpperCase[RandomSample[DictionaryLookup[],1][[1]]],ToString@ToUpperCase[RandomSample[DictionaryLookup[],2]]},
"notset"->{ToString@"JUICE",RandomChoice@CharacterRange["a","z"],ToString@"OK"}

|>
,

Hold@<|
"set"->{ToString@N@Sqrt[3],ToString@N@Sqrt[5],ToString@N@Sqrt[6],ToString@N@E,ToString@N@Pi},
"notset"->{ToString@"JUICE",RandomChoice@CharacterRange["a","z"],ToString@N@Sqrt[11]}

|>
,

Hold@<|
"set"->(ToString[#,TraditionalForm]&/@{{a,a},{a,b},{b,a},{b,b}})(*paran has to be here*),
"notset"->RandomSample[{ToString[{a,1},TraditionalForm],ToString[{b,1},TraditionalForm],ToString[{1,1},TraditionalForm]} ,3]

|>
,
Hold@<|
"set"->{ToString@"MILK",ToString@"SUNGLASSES",ToString@"TOMATO",RandomChoice@CharacterRange["Α","Ω"],ToString@"f(x) = x"},
"notset"->{ToString@"JUICE",ToString@"GLASS",RandomChoice@CharacterRange["a","z"],ToString@"f(x) = 2x"}

|>
,

Hold@<|
"set"->{RandomChoice@CharacterRange["h","z"],ToString@RandomInteger[20,1][[1]],RandomChoice@CharacterRange["λ","ω"],ToString@RandomInteger[20,1][[1]],ToString@RandomInteger[20,1][[1]],ToString@RandomInteger[20,1][[1]], RandomChoice@CharacterRange["Α","Ω"]},
"notset"->{RandomChoice@CharacterRange["α","κ"],ToString@N@Sqrt[2], RandomChoice@CharacterRange["a","g"],ToString@N@Pi}

|>
,

Hold@<|
"set"->{,ToString[(({{a, a}, {b, a}})),TraditionalForm],ToString@N@Pi, RandomChoice@CharacterRange["Α","Ω"],,,Plot3D[{x^2+y^2,-x^2-y^2},{x,-2,2},{y,-2,2},RegionFunction->Function[{x,y,z},x^2+y^2≤4],BoxRatios->Automatic,ImageSize->30,Ticks->None,Mesh->None,Boxed->False,Axes->False]},
"notset"->{,RandomChoice@{ToString[(({{a, a}, {b, b}})),TraditionalForm],ToString[(({{b, a}, {b, a}})),TraditionalForm]},RandomChoice@CharacterRange["a","z"] }

|>

,

Hold@<|
"set"->(ToString[#,TraditionalForm]&/@{(({{a, a}, {a, a}})),(({{a, a}, {a, b}})),(({{a, a}, {b, a}})),(({{a, a}, {b, b}})),(({{a, b}, {a, a}})),(({{a, b}, {a, b}})),(({{a, b}, {b, a}})),(({{a, b}, {b, b}})),(({{b, a}, {a, a}})),(({{b, a}, {a, b}})),(({{b, a}, {b, a}})),(({{b, a}, {b, b}})),(({{b, b}, {a, a}})),(({{b, b}, {a, b}})),(({{b, b}, {b, a}})),(({{b, b}, {b, b}}))})(*paran has to be here*),
"notset"->RandomSample[{ToString[(({{a, c}, {b, b}})),TraditionalForm],ToString[(({{c, a}, {b, a}})),TraditionalForm],ToString[(({{1, a}, {b, a}})),TraditionalForm],ToString[(({{a, a}, {b, 1}})),TraditionalForm]} ,3]

|>

}


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

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



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

{answers,options}=s;

text=vars["text"];
{set1,set2}=ToExpression@vars["vars"][[1]];
Column[{

ToExpression@text[[1]],
Row[{Row[{Column[{options[[1]]<>"i)"}],ToExpression@text[[2]]}]}] ,
set1,
"Which set below is a subset:",
answers[[1]],

Spacer@100(*,
Row[{Row[{Column[{options[[2]]<>")"}],ToExpression@text[[3]]}],Pane[answers[[2]],BaselinePosition->Scaled[0.2]]}] *)


}]


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




variation1=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{key,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,choices,set1,set2,notset,wrong1,wrong2,wrong3,w1,w2,w3,set},


question=RandomChoice[textfghjkl["0"]];

(*a*)

key=RandomChoice[Keys[textfghjkl["1"]]];
text=RandomChoice[textfghjkl["1"][key]];

Which[key=="1.1", 
set=RandomChoice@(listfghjkl[key]);
set1=ReleaseHold@(set)["set"];  (* choose a set from a list *)
set1=RandomSample[set1,Length@set1];
notset=ReleaseHold@(set)["notset"];  
set2=RandomChoice@Subsets[set1,{RandomInteger[{3,4}]}]; (*choose a random subset of size ≤4*)
wrong1=Drop[set2,1]~Join~{RandomChoice@notset};
wrong2=Drop[set2,-1]~Join~{RandomChoice@notset};
wrong3=Drop[set2,{2}]~Join~{RandomChoice@notset};
{a,b,w1,w2,w3}={ToString[set1,InputForm],ToString[set2,InputForm],ToString[wrong1,InputForm],ToString[wrong2,InputForm],ToString[wrong3,InputForm]};
vars={a,b};

sol=set2;(*ToString@SubsetQ[set1,set2];*)

choices=RandomSample[{
w1,
w2,
w3,
b},4];

parta={StringReplace[text, { "@a"->a,"@b"->b}],vars,sol,choices} ;


];


vars=ToString[<|"text"->{question, parta[[1]](*,partb[[1]]*)},"vars"->{ parta[[2]](*,partb[[2]]*)}, "sol"->{ parta[[3]](*,partb[[3]]*)},"choices"->{ parta[[4]](*,partb[[4]]*)}|>,InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ parta[[2]](*,partb[[2]]*)}, { parta[[3]](*,partb[[3]]*)},{ parta[[4]](*,partb[[4]]*)}}


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


solution1=data1<>data2<>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},





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



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

}, 
{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={ 
{""
},
{Null}
};

Panel[Grid[Transpose[body]]]

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

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

ToExpression@libGUI;
ToExpression@libIO;
ToExpression@libML;
panelsMIX={ 

StringReplace[qCanvasPOP1,{"pn0"->ToString[1],"proc0"->proc1,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO31}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick","logo"->ToString[,InputForm]}]

};

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

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

{canvas,vars,sol,choices}=ReleaseHold[ToExpression[StringReplace[variation1,{"canvasZ"->canvas1,"fghjkl"->ToString[1]}]]];