(* ::Package:: *) BeginPackage["AP`"]; (* Author Dara O Shayda, Nov 2014 - Present *) qPanel1::usage = "Sample question"; qPanel2::usage = "Sample question"; qPanel3::usage = "Sample question"; qPanel4::usage = "Sample question"; qPanel5::usage = "Sample question"; qPanel6::usage = "Sample question"; qPanel7::usage = "Sample question"; qPanel8::usage = "Sample question"; qSendHD::usage = "Send the clicks out into hard disk"; readName::usage="read student ID"; examIDString = ""; examIDString2 = "POG230, Sept 2014, Prof.Daniel Rubenson"; examName = "Probability Module"; examName2 = "Probability"; Begin["`Private`"]; qMagnification = 1.2; bigNumber = 1000102010004455; (* [[2]] told me, I told [[3]], [[4]] book, it is all [[5]] *) qNamesList={{"Boza", "he", "him", "his", "his"}, {"Dara", "he", "him", "his", "his"} , {"Jack", "he", "him", "his", "his"}, {"Ginger", "she", "her", "her", "hers"}, {"Wayne", "he", "him", "his", "his"}, {"Spomenka", "she", "her", "her", "hers"}, {"George", "he", "him", "his", "his"}, {"Kevin", "he", "him", "his", "his"}, {"Tina", "she", "her", "her", "hers"}, {"Lucia", "she", "her", "her", "hers"}, {"Ahmad", "he", "him", "his", "his"},{"Abaz", "he", "him", "his", "his"}}; qNumList={{"one",1}, {"two",2}, {"three",3}, {"four",4}, {"five",5}, {"six",6}, {"seven",7}, {"eight",8}, {"nine",9}, {"ten",10}}; qColorList={"red", "green", "blue", "yellow", "black", "white", "pink", "brown", "purple"}; qRandList[list0_]:=list0[[RandomInteger[{1, Length[list0]}]]] qRepeats [list_]:=Tally[list][[All,2]]=== ConstantArray[1,Length[list]] noRepeats[a_, list_, n_]:=Module[{m}, m=0; While[m!=n, m=Length[l=DeleteDuplicates[Join[{a},RandomSample[list,n]]]]]; l ] not0[x_]:=If[x==0, 1, x] qCaps[x0_]:=Module[{x=x0}, x=Characters[x]; StringJoin[Join[{ToUpperCase[x[[1]]]}, Drop[x,1]]] ] qTryAgainNOT[n_]:="" qNum = 0; (* number of questions *) qFlush[text_,id_]:=Module[{s,fname}, (*fname=FileNameJoin[{$TemporaryDirectory,StringReplace[DateString[], {" "->"_", ":"->"_"}]<>"symbolix.txt"}];*) fname=FileNameJoin[{$UserDocumentsDirectory,If[id==="","NOID",StringDrop[StringDrop[id,1],-1]]<>StringReplace[DateString[], {" "->"_", ":"->"_"}]<>"symbolix.txt"}]; s=OpenWrite[fname]; Write[s,text]; {Close[s], fname} ] qAppend[text_]:=Module[{s,fname}, (*fname=FileNameJoin[{$TemporaryDirectory,StringReplace[DateString[], {" "->"_", ":"->"_"}]<>"symbolix.txt"}];*) fname=FileNameJoin[{$UserDocumentsDirectory,"DARADARADARA"<>"symbolix.txt"}]; s=OpenAppend[fname]; Write[s,text]; {Close[s], fname} ] qFlush2[dir_, prefix_,text_]:=Module[{s,fname}, fname=FileNameJoin[{dir,prefix<>"symbolix.txt"}]; s=OpenWrite[fname]; Write[s,text]; Close[s] ] writeID[id_]:=Module[{s,fname}, fname=FileNameJoin[{$UserDocumentsDirectory,"id"<>"symbolix.txt"}]; s=OpenWrite[fname]; Write[s,id]; {Close[s], fname}; ] readID[]:=Module[{s,fname}, fname=FileNameJoin[{$UserDocumentsDirectory,"id"<>"symbolix.txt"}]; Off[Import::nffil]; If[Import[fname,"Text"]===$Failed, "",Import[fname,"Text"]] ] qSendHD[]:=DynamicModule[{status="",a, body,text,ret1,ret2,tmp="",msg,res=False, track,res2,arg,Gg2, Gg3,qClicks,q,first,studentID}, Manipulate[ Refresh[If[first==True,studentID=readID[], If[readID[]==="",studentID,studentID=readID[] ]],UpdateInterval->1]; text=Dynamic[If[studentID=="", "Student Unidentified", "ID="<>studentID]<>"\n"<>status]; body={{Dynamic[If[res==True,Text[Style["Checked Marks Indicate Correct Answers\n"<>"\nTo Track this test: email "<>ToString[track]<>", "<>IntegerString[Hash[ToString[Gg2]<>ToString[track]<>"Mehran1339","MD5"],16]<>" to Deidre Lam \n"<>"Test results stored in file: "<>res2[[2]],Red,Background->Yellow]], ""]],Dynamic[If[res==True,CheckboxBar[Range[qNum]*Gg3,Range[qNum], Appearance->"Vertical",Enabled->False], ""]], Dynamic[Which[(Mean[Gg3] >= 0.8)&& (res == True), "\n\!\(\* StyleBox[\"Congratulations\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"!\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"You\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"passed\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"the\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)"<> examName <>" \!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"..\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\".\",\nFontColor->RGBColor[1, 0, 0]]\)\n\!\(\* StyleBox[\"Grade\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\":\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)"<>ToString[Ceiling[qTrunc4[Mean[Gg3]]*100]],(Mean[Gg3] < 0.8)&& (res == True), "\n \!\(\* StyleBox[\"Please\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"study\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"the\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)"<> examName <>" \!\(\* StyleBox[\"and\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"write\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"this\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"test\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\" \",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\"again\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\".\",\nFontColor->RGBColor[1, 0, 0]]\)\n\!\(\* StyleBox[\"Grade\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\* StyleBox[\":\",\nFontColor->RGBColor[1, 0, 0]]\) "<>ToString[Ceiling[qTrunc4[Mean[Gg3]]*100]],True,""]]},{"","",""}}; Deploy[ Style[Panel[Grid[Transpose[body],Alignment->Left,Spacings->{4,0.5}(*,ItemSize->20)*)],text,ImageMargins->1],DefaultOptions->{InputField->{ContinuousAction->True},FontSize->Large}]], {{a, 0,""},(*Style[Dynamic[ *) Button["Send Answers",Off[Import::nffil];Off[DeleteFile::nffil]; If[ first == True,q=Import[FileNameJoin[{$UserDocumentsDirectory,"DARADARADARA"<>"symbolix.txt"}],"List"]; Gg2=DeleteDuplicates[Table[ToExpression[q[[i]]],{i, 1, Length[q]}]]; Table[qClicks[[Gg2[[i]][[1]]]]=Gg2[[i]],{i,1 Length[Gg2]}]]; studentID=readID[]; Gg2=qClicks; Gg3=Gg2[[1;;qNum,2]]; res=True; arg=studentID<>" , "<>examName2<>" , "<>ToString[Ceiling[qTrunc4[Mean[Gg3]]*100]]<>" , "<>ToString[Gg2]<>" , "<>examIDString2<>" , "<>DateString[]<>" , "<>ToString[track]<>" , "<>IntegerString[Hash[ToString[Gg2]<>ToString[track]<>"gilan1339","MD5"],16];res2=qFlush[arg,studentID]; URLFetch["http://symbolicexams.lossofgenerality.com/wp-content/plugins/test-receiver/results.php","Parameters"->{"results"->studentID<>" , "<>examName2<>" , "<>ToString[Ceiling[qTrunc4[Mean[Gg3]]*100]]<>" , "<>ToString[Gg2]<>" , "<>examIDString2<>" , "<>DateString[]<>" , "<>ToString[track]<>" , "<>IntegerString[Hash[ToString[Gg2]<>ToString[track]<>"Mehran1339","MD5"],16]},"ReadTimeout"->10,"ConnectTimeout"->50,"Method"->"POST"]; status="Answers Sent, Good Luck!\n";If[ first==True,DeleteFile[FileNameJoin[{$UserDocumentsDirectory,"DARADARADARA"<>"symbolix.txt"}]]];first=False;DeleteFile[FileNameJoin[{$UserDocumentsDirectory,"id"<>"symbolix.txt"}]];(*<>ToString[res2[[1]]]*)(*Clear["Global`*"];ClearAll[qClickPlus,qClick,readName]*),Method->"Queued" ](*],DynamicEvaluationTimeout->20]*) &}, TrackedSymbols->Manipulate, SaveDefinitions->True,AppearanceElements->None,SynchronousUpdating->False,ContinuousAction->False, Initialization:>(qClicks = {{1, 0, -1, ""}, {2, 0, -1, ""}, {3, 0, -1, ""}, {4, 0, -1, ""}, {5, 0, -1, ""}, {6, 0, -1, ""},{7, 0, -1, ""},{8, 0, -1, ""},{9, 0, -1, ""},{10, 0, -1, ""}};track=RandomInteger[{100000,900000}];first=True;studentID="")] ] readName[]:=DynamicModule[{x="",a, body,inputs, text=Null,studentID}, Manipulate[ (* If has to use TrueQ[]!!! *) text=Dynamic[If[TrueQ[x==Null], "", "ID Registered: "<>studentID]]; inputs=InputField[Dynamic[x], String, FieldHint->"Enter your ID"]; body={{inputs,Text[Style[examName<>"\n"<>examIDString,Red]]},{"",""}}; (*Refresh[studentID=studentID2 ,UpdateInterval->2,TrackedSymbols:>{studentID2}];*) Deploy[ Style[Panel[Grid[Transpose[body],Alignment->Left,Spacings->{4,0.5}(*,ItemSize->20)*)],text,ImageMargins->1],DefaultOptions->{InputField->{ContinuousAction->True},FontSize->Large}]], {{a, 0,""}, Button["Press To Register ID", studentID = x;writeID[studentID]]&}, TrackedSymbols->Manipulate, SaveDefinitions->True,AppearanceElements->None,SynchronousUpdating->False, Initialization:>(Off[Import::nffil];Off[DeleteFile::nffil];qClicks = {{1, 0, -1, ""}, {2, 0, -1, ""}, {3, 0, -1, ""}, {4, 0, -1, ""}, {5, 0, -1, ""}, {6, 0, -1, ""},{7, 0, -1, ""},{8, 0, -1, ""},{9, 0, -1, ""},{10, 0, -1, ""}};qNum=0;studentID=""; DeleteFile[FileNameJoin[{$UserDocumentsDirectory,"DARADARADARA"<>"symbolix.txt"}]];DeleteFile[FileNameJoin[{$UserDocumentsDirectory,"id"<>"symbolix.txt"}]])] ] randDrop[list0_,n_]:=Module[{list2,list=list0},Table[list2=Drop[list,{RandomInteger[{1,Length[list]}]}];list=list2,{i,1, n}] ] randDrop2[list0_,n_]:=Module[{list2,list=list0},Table[list2=Drop[list,{RandomInteger[{2,Length[list]}]}];list=list2,{i,1, n}] ] randDrop3[list0_,n_]:=Module[{list2,list=list0, list3={},j},Table[list2=Drop[list,{RandomInteger[{2,Length[list]}]}];AppendTo[list3,j];list=list2,{i,1, n}]; {list2, list3} ] listBox[qa_,size_,color_]:=Pane[Column[Flatten[Table[qa[[i]], {i, 1, Length[qa]}],1],Background->{color},Frame->True],ImageSize->size,Scrollbars->True] f1[x_]:=x^3 f2[x_]:=Sin[x] f3[x_]:=Cos[x] f4[x_]:=x^2 f5[x_]:=Log[x] f6[x_]:=Exp[x] f7[x_]:=Exp[-x] f8[x_]:=Tan[x] f9[x_]:=ArcTan[x] f10[x_]:=1/x f11[x_]:=x flist={f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11}; fForm={f1->"x^3",f2->"Sin[x]", f3->"Cos[x]", f4->"x^2",f5->"Log[x]", f6->"Exp[x]",f7->"Exp[-x]",f8->"Tan[x]", f9->"ArcTan[x]", f10->"1/x", f11->"x"} ; qPanelsolution1[vars_,answerNum_]:=DynamicModule[{y,body,index,f,form,x}, {index,f,form}=vars; (* body is an array with a as index to shuffle the solutions *) body= { (*1*) {{ "After looking into our slope field we need to find which function it resembles.", "To do this we need to follow the arrows:", (*ListVectorPlot[Table[{1,f'[x+0.000001]}, {x,-5,5,1},{y,-5,5,1}],Background->White,StreamPoints -> Fine(*Automatic*),StreamStyle\[Rule] Orange,VectorPoints->All,(*FrameLabel->{"X","Y"},*)DataRange->{{-5,5},{-5,5}},Axes -> True,AxesLabel -> {"x", "y"}],*) ListVectorPlot[Table[Normalize[{1,f'[x+0.000001]}], {x,-5,5,1},{y,-5,5,1}],Background->White,StreamPoints -> Fine(*Automatic*),StreamStyle-> Orange,VectorPoints->All,(*FrameLabel->{"X","Y"},*)DataRange->{{-5,5},{-5,5}},Axes -> True,AxesLabel -> {"x", "y"}], "It is similar to "<>form<>"\n", "To be sure if it is a right answer check:", "For "<>form<>" the field vectors are (1, "<>ToString[ "\!\(\*FractionBox[\(\[DifferentialD]f \((x)\)\), \(\[DifferentialD]x\)]\)" ,TraditionalForm]<>"):", "(1, "<>ToString[f'[x]/.{x->"x"}, TraditionalForm]<>")", ListVectorPlot[Table[{1,f'[x+0.000001]}, {x,-5,5,1},{y,-5,5,1}],VectorPoints->All,(*FrameLabel->{"X","Y"},*)DataRange->{{-5,5},{-5,5}},Axes -> True,AxesLabel -> {"x", "y"}], (* ListVectorPlot[Table[{1,f'[x+0.000001]}, {x,-3,3,1},{y,-3,3,1}],VectorPoints->All,FrameTicks->None], *) "Normalize each vector, some might be too small or large:", ListVectorPlot[Table[Normalize[{1,f'[x+0.000001]}], {x,-5,5,1},{y,-5,5,1}],VectorPoints->All,(*FrameLabel->{"X","Y"},*)DataRange->{{-5,5},{-5,5}},Axes -> True,AxesLabel -> {"x", "y"}], (* ListVectorPlot[Table[Normalize[{1,f'[x+0.000001]}], {x,-3,3,1},{y,-3,3,1}],VectorPoints->All,FrameTicks->None] *) "After knowing the slope field and function "<>ToString[f'[x]/.{x->"x"}, TraditionalForm]<>" check if it fits together: \n", y=f'[x]/.{x->2}; "For example value of function in point (2,2) is "<>ToString[NumberForm[N[y,3],3], TraditionalForm], "It should correspond to slope of vector in point (2,2)", "In that way check some points to be sure if your answer is truth." }, {Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null}}, (*2*) {{ "","" }, {Null,Null}} }; Panel[Grid[Transpose[body[[index]]]]] ] qPanelVariation1[pn_, vars_]:=Module[{variations,index,f,form}, {index,f,form}=vars; answers=noRepeats[f, flist, 4]; variations={{Which[ index==1, "The Slope Field for a certain differential equation is shown below. Which of the following could be a spicific solution to that differential equation?" ]}, {Which[ index==1, "Which function matches the following Slope Field?" ]} }; ToString[pn]<>". "<>qRandList[variations] ] qPanelAnswers1[vars_]:=Module[{index,f,form,answers}, {index,f,form}=vars; answers=noRepeats[f, flist, 5]; { Which[ index==1 ,ToString[ToExpression[answers[[2]]/.fForm],TraditionalForm] ], Which[ index==1 ,ToString[ToExpression[answers[[3]]/.fForm],TraditionalForm] ], Which[ index==1 ,form ], Which[ index==1 ,ToString[ToExpression[answers[[4]]/.fForm],TraditionalForm] ], Which[ index==1 ,ToString[ToExpression[answers[[5]]/.fForm],TraditionalForm] ] } ] qPanelTRYAGAIN1[]:=Module[{index,f}, index=RandomInteger[{1,1}]; f=qRandList[flist]; (* increase 1 for more complex problem *) {index , f, ToString[ToExpression[f/.fForm],TraditionalForm]} ] qPaneHint1[vars_]:=Module[{body,index,f,form}, {index ,f,form}=vars; body={{ " The field vectors are (1, "<>ToString[ "\!\(\*FractionBox[\(\[DifferentialD]f \((x)\)\), \(\[DifferentialD]x\)]\)" ,TraditionalForm]<>")", "Normalize the said vector to avoid very short or very long vectors." }, {Null,Null}}; Panel[Grid[Transpose[body]]] ] qPanelEXPR1[vars_]:=Module[{index,f,form}, {index ,f,form}=vars; VectorPlot[Normalize[{1,f'[x]}],{x,-5,5},{y,-5,5},VectorScale->0.03,VectorPoints->Fine,ImageSize->400,Axes -> True,AxesLabel -> {"x", "y"}] ] qPanel1[pn0_,diag0_]:= DynamicModule[{xxx, pn=pn0,text,person,variations,A1=False,B1=False,C1=False,D1=False,E1=False,vars,answer,b,bb,c,cc,aa,a,d,dd,rem,m,n,myEnabled=True,text2,body, answers, checks,answersShuffled,checksShuffled,index,answerStudent,tryAgain=True, state=False, stateH=False,diag=diag0,g,answerNum=0 }, qNum +=1; If[diag==False, (* this is diagnosis training test *) Style[Manipulate[ xxx=xxx; (* kludge *) vars=qPanelTRYAGAIN1[]; text=qPanelVariation1[pn, vars]; answer="?"; answerNum=0; answerStudent=Dynamic[Which [ A1,answerNum=1;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", C1,answerNum=3;qClick[pn];qTryAgainNOT[pn];myEnabled=False;text<>"\n\nAnswer Correct", B1,answerNum=2;qClickPlus[pn];myEnabled=False;text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", D1, answerNum=4;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", E1, answerNum=5;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", True, text<>"\n\nAnswer ?"] ]; answers=qPanelAnswers1[vars]; checks = {Checkbox[Dynamic[A1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[B1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[C1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[D1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[E1],Enabled->Dynamic[myEnabled]]}; (* Shuffle the answer keys *) index = RandomSample[Range[Length[answers]]]; answersShuffled = Table[answers[[index[[i]]]], {i, 1,Length[answers]}]; checksShuffled = Table[checks[[index[[i]]]], {i, 1,Length[answers]}]; body = { (* First row/colum the answer key *) {"A","B","C","D","E"}, (* First row/colum the proposed answers key *) answersShuffled, (* First row/colum the answer check boxes*) checksShuffled }; (* Kludge: answerStudent has problem with <>, so concatenated earlier*) Deploy[ Style[Panel[Grid[Transpose[body],Alignment->Left],Column[{answerStudent,qPanelEXPR1[vars]}],ImageMargins->10]]], {{xxx,1,""}, (* initial value of xxx, xxx=RandomReal[0.5] has to be in the button or else the test would not repeat*) Grid[{ {OpenerView[{Button["New Question",qTryAgain[pn];xxx=RandomReal[0.5];vars=qPanelTRYAGAIN1[];myEnabled=True;A1=False; B1=False;C1=False; D1= False; E1= False], "Try again"}], OpenerView[{Button["Hint",qTryAgain[pn];stateH=Not[stateH]],qPaneHint1[vars]},stateH], OpenerView[{Button["Solution",qTryAgain[pn];state=Not[state]],qPanelsolution1[vars,answerNum]},state]} ,{Null,Null,Null}}] &}, TrackedSymbols->Manipulate, SaveDefinitions->True,AppearanceElements->None,Initialization:>(qClicks = {{1, 0, 0, ""}, {2, 0, 0, ""}, {3, 0, 0, ""}, {4, 0, 0, ""}, {5, 0, 0, ""}, {6, 0, 0, ""},{7, 0, 0, ""},{8, 0, 0, ""},{9, 0, 0, ""},{10, 0, 0, ""}})] (*Manipulate*) , DynamicBoxOptions -> {BaseStyle -> Magnification -> qMagnification}] , (* Else if actual test *) Style[Manipulate[ vars=qPanelTRYAGAIN1[]; text=qPanelVariation1[pn,vars]; answer="?"; answerStudent=Dynamic[Which [A1,myEnabled=False;qClickPlus[pn];text<>"",C1,qClick[pn];qTryAgainNOT[pn];myEnabled=False;text<>"",B1,qClickPlus[pn];myEnabled=False;text<>"",D1, myEnabled=False;qClickPlus[pn];text<>"", True, text<>""]]; answers=qPanelAnswers1[vars]; checks = {Checkbox[Dynamic[A1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[B1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[C1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[D1],Enabled->Dynamic[myEnabled]]}; (* Shuffle the answer keys *) index = RandomSample[Range[Length[answers]]]; answersShuffled = Table[answers[[index[[i]]]], {i, 1,Length[answers]}]; checksShuffled = Table[checks[[index[[i]]]], {i, 1,Length[answers]}]; body = { (* First row/colum the answer key *) {"A","B","C","D"}, (* First row/colum the proposed answers key *) answersShuffled, (* First row/colum the answer check boxes*) checksShuffled }; (* Kludge: answerStudent has problem with <>, so concatenated earlier*) Deploy[ Style[Panel[Grid[Transpose[body],Alignment->Left],Column[{answerStudent,qPanelEXPR1[vars]}],ImageMargins->10]]], "", TrackedSymbols->Manipulate, SaveDefinitions->True, AppearanceElements->None,SynchronousUpdating->False(*,Initialization:>(qClicks = {{1, 0, 0, ""}, {2, 0, 0, ""}, {3, 0, 0, ""}, {4, 0, 0, ""}, {5, 0, 0, ""}, {6, 0, 0, ""},{7, 0, 0, ""},{8, 0, 0, ""},{9, 0, 0, ""},{10, 0, 0, ""}})*)] (*Manipulate*) , DynamicBoxOptions -> {BaseStyle -> Magnification -> qMagnification}] ] ] qPanelsolution2[vars_,answerNum_]:=DynamicModule[{body,index,f,form,x,a,b,c,d,e,sol,expr}, {index , a,b,c,d,sol}=vars; (* body is an array with a as index to shuffle the solutions *) body= { (*1*) {{ ToString[ \!\(\*UnderscriptBox[\("\"\), \("\0\>"\)]\),TraditionalForm]<>ToString[(ToString[(a*x+b*Sin[c*x])/.{x->"x"},TraditionalForm])/(ToString[(Exp[d*x]-1)/.{x->"x"},TraditionalForm]),TraditionalForm]<>"=["<> Which[ ((a>0 && b>0 && c>0) || (a>0 && b<0 && c<0)),ToString[(ToString[(a*x)/.If[Abs[a]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm]<>"+"<>ToString[(b*Sin[c*x])/.If[Abs[c]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm])/(ToString[(Exp[d*x]-1)/.If[Abs[d]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm]),TraditionalForm], ((a<0 && b>0 && c>0) || (a<0 && b<0 && c<0)),ToString[(ToString[(b*Sin[c*x])/.If[Abs[c]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm]<>ToString[(a*x)/.If[Abs[a]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm])/(ToString[(Exp[d*x]-1)/.If[Abs[d]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm]),TraditionalForm], ((a>0 && b<0 && c>0) || (a>0 && b>0 && c<0) || (a<0 && b<0 && c>0) ||(a<0 && b>0 && c<0)),ToString[(ToString[(a*x)/.If[Abs[a]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm]<>ToString[(b*Sin[c*x])/.If[Abs[c]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm])/(ToString[(Exp[d*x]-1)/.If[Abs[d]==1,{x->"0"},{x->"\[Cross] 0"}],TraditionalForm]),TraditionalForm] ] <>"]= ["<>ToString[HoldForm["0-0"/"1-1"], TraditionalForm]<>"]= ["<>ToString[HoldForm["0"/"0"], TraditionalForm]<>"]", (* ToString[ToString[(a*x+b*Sin[c*x])/.{x->"x"},TraditionalForm]/(ToString["\!\(\*FractionBox[\(\[DifferentialD]\), \(\[DifferentialD]x\)]\)("<>ToString[(Exp[d*x]-1)/.{x->"x"},TraditionalForm]<>")",TraditionalForm]),TraditionalForm]<>"="<>ToString[ToString[D[(a*x+b*Sin[c*x]),x]/.{x->"x"},TraditionalForm]/ToString[D[(Exp[d*x]-1),x]/.{x->"x"},TraditionalForm],TraditionalForm], *) "now use L'Hopital rule:", ToString[ \!\(\*UnderscriptBox[\("\"\), \("\0\>"\)]\),TraditionalForm]<>ToString[ToString["\!\(\*FractionBox[\(\[DifferentialD]\), \(\[DifferentialD]x\)]\)("<>ToString[(a*x+b*Sin[c*x])/.{x->"x"},TraditionalForm]<>")",TraditionalForm]/(ToString["\!\(\*FractionBox[\(\[DifferentialD]\), \(\[DifferentialD]x\)]\)("<>ToString[(Exp[d*x]-1)/.{x->"x"},TraditionalForm]<>")",TraditionalForm]),TraditionalForm]<>"="<>ToString[ \!\(\*UnderscriptBox[\("\"\), \("\0\>"\)]\),TraditionalForm]<>ToString[ToString[D[(a*x+b*Sin[c*x]),x]/.{x->"x"},TraditionalForm]/ToString[D[(Exp[d*x]-1),x]/.{x->"x"},TraditionalForm],TraditionalForm], "Approach x to limit 0:", expr=ToString[ToString[D[(a*x+b*Sin[c*x]),x]/.{x->"x"},TraditionalForm]/ToString[D[(Exp[d*x]-1),x]/.{x->"x"},TraditionalForm],TraditionalForm]; ToString[ToString[ \!\(\*UnderscriptBox[\("\"\), \("\0\>"\)]\),TraditionalForm]<>expr,TraditionalForm]<>"="<>ToString[sol, TraditionalForm] }, {Null,Null,Null,Null,Null}}, (*2*) {{ "","" }, {Null,Null}} }; Panel[Grid[Transpose[body[[index]]]]] ] qPanelVariation2[pn_, vars_]:=Module[{variations,index,f,form,a,b,c,d,e,sol,x,expr}, {index , a,b,c,d,sol}=vars; expr=ToString[(a*"x"+b*Sin[c*"x"])/(Exp[d*"x"]-1),TraditionalForm]; variations={{Which[ index==1, "Find:\n"<>ToString[ToString[ \!\(\*UnderscriptBox[\("\"\), \("\0\>"\)]\),TraditionalForm]<>expr,TraditionalForm] ]}, {Which[ index==1, "What is the following Limit:\n"<>ToString[ToString[ \!\(\*UnderscriptBox[\("\"\), \("\0\>"\)]\),TraditionalForm]<>expr,TraditionalForm] ]} }; ToString[pn]<>". "<>qRandList[variations] ] qPanelAnswers2[vars_]:=Module[{index,f,form,answers,a,b,c,d,e,sol,x}, {index , a,b,c,d,sol}=vars; { Which[ index==1 ,ToString[sol+1,TraditionalForm] ], Which[ index==1 ,ToString[sol+2,TraditionalForm] ], Which[ index==1 ,ToString[sol,TraditionalForm] ], Which[ index==1 ,ToString[sol-1,TraditionalForm] ], Which[ index==1 ,ToString[sol+3,TraditionalForm] ] } ] qPanelTRYAGAIN2[]:=Module[{index,f,a,b,c,d,e,sol,x}, (* increase 1 for more complex problem *) index=RandomInteger[{1,1}]; a=not0[RandomInteger[{-5,5}]]; b=not0[RandomInteger[{-5,5}]]; c=not0[RandomInteger[{-5,5}]]; d=not0[RandomInteger[{-5,5}]]; sol=Limit[(a*x+b*Sin[c*x])/(Exp[d*x]-1),x->0]; {index , a,b,c,d,sol} ] qPaneHint2[vars_]:=Module[{body,index,f,form,a,b,c,d,e,sol}, {index , a,b,c,d,sol}=vars; body={{ "Use L'Hopital Rule", "" }, {Null,Null}}; Panel[Grid[Transpose[body]]] ] qPanelEXPR2[vars_]:=Module[{index,f,form,a,b,c,d,e,sol,x,expr}, {index , a,b,c,d,sol}=vars; ] qPanel2[pn0_,diag0_]:= DynamicModule[{xxx, pn=pn0,text,person,variations,A1=False,B1=False,C1=False,D1=False,E1=False,vars,answer,b,bb,c,cc,aa,a,d,dd,rem,m,n,myEnabled=True,text2,body, answers, checks,answersShuffled,checksShuffled,index,answerStudent,tryAgain=True, state=False, stateH=False,diag=diag0,g,answerNum=0 }, qNum +=1; If[diag==False, (* this is diagnosis training test *) Style[Manipulate[ xxx=xxx; (* kludge *) vars=qPanelTRYAGAIN2[]; text=qPanelVariation2[pn, vars]; answer="?"; answerNum=0; answerStudent=Dynamic[Which [ A1,answerNum=1;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", C1,answerNum=3;qClick[pn];qTryAgainNOT[pn];myEnabled=False;text<>"\n\nAnswer Correct", B1,answerNum=2;qClickPlus[pn];myEnabled=False;text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", D1, answerNum=4;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", E1, answerNum=5;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", True, text<>"\n\nAnswer ?"] ]; answers=qPanelAnswers2[vars]; checks = {Checkbox[Dynamic[A1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[B1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[C1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[D1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[E1],Enabled->Dynamic[myEnabled]]}; (* Shuffle the answer keys *) index = RandomSample[Range[Length[answers]]]; answersShuffled = Table[answers[[index[[i]]]], {i, 1,Length[answers]}]; checksShuffled = Table[checks[[index[[i]]]], {i, 1,Length[answers]}]; body = { (* First row/colum the answer key *) {"A","B","C","D","E"}, (* First row/colum the proposed answers key *) answersShuffled, (* First row/colum the answer check boxes*) checksShuffled }; (* Kludge: answerStudent has problem with <>, so concatenated earlier*) Deploy[ Style[Panel[Grid[Transpose[body],Alignment->Left],Column[{answerStudent,qPanelEXPR2[vars]}],ImageMargins->10]]], {{xxx,1,""}, (* initial value of xxx, xxx=RandomReal[0.5] has to be in the button or else the test would not repeat*) Grid[{ {OpenerView[{Button["New Question",qTryAgain[pn];xxx=RandomReal[0.5];vars=qPanelTRYAGAIN2[];myEnabled=True;A1=False; B1=False;C1=False; D1= False; E1= False], "Try again"}], OpenerView[{Button["Hint",qTryAgain[pn];stateH=Not[stateH]],qPaneHint2[vars]},stateH], OpenerView[{Button["Solution",qTryAgain[pn];state=Not[state]],qPanelsolution2[vars,answerNum]},state]} ,{Null,Null,Null}}] &}, TrackedSymbols->Manipulate, SaveDefinitions->True,AppearanceElements->None,Initialization:>(qClicks = {{1, 0, 0, ""}, {2, 0, 0, ""}, {3, 0, 0, ""}, {4, 0, 0, ""}, {5, 0, 0, ""}, {6, 0, 0, ""},{7, 0, 0, ""},{8, 0, 0, ""},{9, 0, 0, ""},{10, 0, 0, ""}})] (*Manipulate*) , DynamicBoxOptions -> {BaseStyle -> Magnification -> qMagnification}] , (* Else if actual test *) Style[Manipulate[ vars=qPanelTRYAGAIN1[]; text=qPanelVariation1[pn,vars]; answer="?"; answerStudent=Dynamic[Which [A1,myEnabled=False;qClickPlus[pn];text<>"",C1,qClick[pn];qTryAgainNOT[pn];myEnabled=False;text<>"",B1,qClickPlus[pn];myEnabled=False;text<>"",D1, myEnabled=False;qClickPlus[pn];text<>"", True, text<>""]]; answers=qPanelAnswers1[vars]; checks = {Checkbox[Dynamic[A1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[B1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[C1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[D1],Enabled->Dynamic[myEnabled]]}; (* Shuffle the answer keys *) index = RandomSample[Range[Length[answers]]]; answersShuffled = Table[answers[[index[[i]]]], {i, 1,Length[answers]}]; checksShuffled = Table[checks[[index[[i]]]], {i, 1,Length[answers]}]; body = { (* First row/colum the answer key *) {"A","B","C","D"}, (* First row/colum the proposed answers key *) answersShuffled, (* First row/colum the answer check boxes*) checksShuffled }; (* Kludge: answerStudent has problem with <>, so concatenated earlier*) Deploy[ Style[Panel[Grid[Transpose[body],Alignment->Left],Column[{answerStudent,qPanelEXPR1[vars]}],ImageMargins->10]]], "", TrackedSymbols->Manipulate, SaveDefinitions->True, AppearanceElements->None,SynchronousUpdating->False(*,Initialization:>(qClicks = {{1, 0, 0, ""}, {2, 0, 0, ""}, {3, 0, 0, ""}, {4, 0, 0, ""}, {5, 0, 0, ""}, {6, 0, 0, ""},{7, 0, 0, ""},{8, 0, 0, ""},{9, 0, 0, ""},{10, 0, 0, ""}})*)] (*Manipulate*) , DynamicBoxOptions -> {BaseStyle -> Magnification -> qMagnification}] ] ] qPanelsolution3[vars_,answerNum_]:=DynamicModule[{body,index,f,form,x,a,b,c,d,e,sol,expr}, {index , a,b,c,d}=vars; (* body is an array with a as index to shuffle the solutions *) body= { (*1*) {{ "If function is differentiable it should be also continuous.", "Only x=0 could be the point of discontinuity, so for x=0: ", ToString[(E^(-c*"x")+d), TraditionalForm]<>"="<>ToString[("a"*"x"+"b"), TraditionalForm], If[Abs[c]!=1 ,ToString[(E^(-c*x)+d)/.{x->"\[Cross] 0"}, TraditionalForm]<>"="<>ToString[("a"*x+"b")/.{x->"0 \[Cross]"}, TraditionalForm],ToString[(E^(-c*x)+d)/.{x->"0"}, TraditionalForm]<>"="<>ToString[("a"*x+"b")/.{x->"0 *"}, TraditionalForm]], ToString[(1+d), TraditionalForm]<>"="<>ToString["b", TraditionalForm], "Now we need to check if left handed deriative is equal right handed derivative in point x=0", "", "In point x=0 for calculate left handed derivative take f(x) = "<>ToString[("a"*"x"+"b"), TraditionalForm], ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(-\)]]\),TraditionalForm]<>ToString[("f(x+h)-f(x)")/("h"), TraditionalForm]<>"="<>ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(-\)]]\),TraditionalForm]<>ToString[ToString["a\[Cross](0+h)"+(1+d),TraditionalForm]<>"-("<>ToString["a\[Cross]0"+(1+d),TraditionalForm]<>")"/("h"),TraditionalForm]<>"="<>ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(-\)]]\),TraditionalForm]<>ToString[("a \[Cross] h")/("h"), TraditionalForm]<>"= a", "", "In point x=0 for calculate right handed derivative take f(x) = "<>ToString[(E^(-c*"x")+d), TraditionalForm], If[Abs[c]!=1,ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(+\)]]\),TraditionalForm]<>ToString[("f(x+h)-f(x)")/("h"), TraditionalForm]<>"="<>ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(+\)]]\),TraditionalForm]<>ToString[ ToString[(E^(-c*"\[Cross](0+h)")+d), TraditionalForm]<>"-("<>ToString[(E^(-c*"\[Cross]0")+d), TraditionalForm]<>")"/("h"),TraditionalForm]<>"="<>ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(+\)]]\),TraditionalForm]<>ToString[ToString[(E^(-c*"\[Cross]h")), TraditionalForm]<>"-"<>ToString["1", TraditionalForm]/("h"),TraditionalForm], ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(+\)]]\),TraditionalForm]<>ToString[("f(x+h)-f(x)")/("h"), TraditionalForm]<>"="<>ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(+\)]]\),TraditionalForm]<>ToString[ ToString[(E^(-c*"(0+h)")+d), TraditionalForm]<>"-("<>ToString[(E^(-c*"0")+d), TraditionalForm]<>")"/("h"),TraditionalForm]<>"="<>ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(+\)]]\),TraditionalForm]<>ToString[ToString[(E^(-c*"h")), TraditionalForm]<>"-"<>ToString["1", TraditionalForm]/("h"),TraditionalForm] ] <>"=\n["<>ToString[HoldForm["0"/"0"],TraditionalForm]<>"] "<>"\!\(\*OverscriptBox[\(=\), \(de\\\ l' Hopital\\\ rule\)]\)"<>ToString[ \!\(\*UnderscriptBox[\("\"\), SuperscriptBox[\("\0\>"\), \(+\)]]\),TraditionalForm]<>If[Abs[c]!=1,ToString[ToString[-c*(E^(-c*"\[Cross]h")), TraditionalForm]/("1"),TraditionalForm],ToString[ToString[-c*(E^(-c*"h")), TraditionalForm]/("1"),TraditionalForm]]<>"="<>ToString[-c,TraditionalForm], "left handed deriative should be equal right handed derivative, so:", ToString["a = ",TraditionalForm]<>ToString[-c,TraditionalForm], "hence", ToString["a + b = ",TraditionalForm]<>ToString[a,TraditionalForm]<>"+("<>ToString[1+d,TraditionalForm]<>")="<>ToString[a+(1+d),TraditionalForm], (* "Take each of the two piecewise equations and set them equal at x=0:", ToString[(E^(-c*"x")+d), TraditionalForm]<>"="<>ToString[("a"*"x"+"b"), TraditionalForm], "Take the derivative of the said two piencewise functions and seth them equal at x=0:", ToString[D[(E^(-c*x)+d),x]/.{x->"x"}, TraditionalForm]<>"="<>ToString[D[("a"*x+"b"),x], TraditionalForm], "Solve these two equations and obtain a and b: "<>ToString[a, TraditionalForm]<>", "<>ToString[b, TraditionalForm], "Thus a+b="<>ToString[a+b,TraditionalForm], *) (*Manipulate[Plot[func3[x]/.{aa\[Rule](a+da),bb\[Rule](b+db),cc->c, dd->d}, {x,-5,5},PlotStyle->All], {da,-Abs[a]-4,Abs[a]+4}, {db,-Abs[b]-4,Abs[b]+4},Initialization:>(da=0;db=0;)]*) Plot[func3[x]/.{aa->a,bb->b,cc->c, dd->d}, {x,-5,5},PlotRange->All] }, {Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null}}, (*2*) {{ "","" }, {Null,Null}} }; Panel[Grid[Transpose[body[[index]]]]] ] qPanelVariation3[pn_, vars_]:=Module[{variations,index,f,form,a,b,c,d,e,sol,x,expr}, {index , a,b,c,d}=vars; expr=ToString[func3["x"]/.{cc->c,dd->d,aa->"a", bb->"b"},TraditionalForm]; variations={{Which[ index==1, "If a functions defined as:\nf(x)="<>ToString[expr,TraditionalForm]<>"\nif f(x) is differentiable, then a+b equals:" ]}, {Which[ index==1, "What should be the value of a+b :\nf(x)="<>ToString[expr,TraditionalForm]<>"\nin order for f(x) to be differentiable:" ]} }; ToString[pn]<>". "<>qRandList[variations] ] qPanelAnswers3[vars_]:=Module[{index,f,form,answers,a,b,c,d,e,sol,x}, {index , a,b,c,d}=vars; { Which[ index==1 ,ToString[a+b+1,TraditionalForm] ], Which[ index==1 ,ToString[a+b+2,TraditionalForm] ], Which[ index==1 ,ToString[a+b,TraditionalForm] ], Which[ index==1 ,ToString[a+b-1,TraditionalForm] ], Which[ index==1 ,ToString[a+b+3,TraditionalForm] ] } ] qPanelTRYAGAIN3[]:=Module[{index,f,a,b,c,d,e,sol,x}, (* increase 1 for more complex problem *) index=RandomInteger[{1,1}]; (* Solve[(D[\[ExponentialE]^(-c*x)+d,x]/.{x\[Rule]0})\[Equal](D[a*x+b,x]/.{x\[Rule]0})&&((\[ExponentialE]^(-c*x)+d)/.{x\[Rule]0})\[Equal]((a*x+b)/.{x\[Rule]0}),{a,b},Reals] shows that {{a\[Rule]-c,b\[Rule]1+d}} for the solution *) c=not0[RandomInteger[{-4,4}]]; d=not0[RandomInteger[{-5,5}]]; {index , -c,1+d,c,d} ] qPaneHint3[vars_]:=Module[{body,index,f,form,a,b,c,d,e,sol}, {index , a,b,c,d}=vars; body={{ "Compute system of equations at 0 for f and f'", "" }, {Null,Null}}; Panel[Grid[Transpose[body]]] ] qPanelEXPR3[vars_]:=Module[{index,f,form,a,b,c,d,e,sol,x,expr}, {index , a,b, c,d}=vars; "" ] func3[x_]:=Piecewise[{{E^(-cc*x)+dd,x>0},{aa*x+bb,x<=0}}] qPanel3[pn0_,diag0_]:= DynamicModule[{xxx, pn=pn0,text,person,variations,A1=False,B1=False,C1=False,D1=False,E1=False,vars,answer,b,bb,c,cc,aa,a,d,dd,rem,m,n,myEnabled=True,text2,body, answers, checks,answersShuffled,checksShuffled,index,answerStudent,tryAgain=True, state=False, stateH=False,diag=diag0,g,answerNum=0 }, qNum +=1; If[diag==False, (* this is diagnosis training test *) Style[Manipulate[ xxx=xxx; (* kludge *) vars=qPanelTRYAGAIN3[]; text=qPanelVariation3[pn, vars]; answer="?"; answerNum=0; answerStudent=Dynamic[Which [ A1,answerNum=1;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", C1,answerNum=3;qClick[pn];qTryAgainNOT[pn];myEnabled=False;text<>"\n\nAnswer Correct", B1,answerNum=2;qClickPlus[pn];myEnabled=False;text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", D1, answerNum=4;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", E1, answerNum=5;myEnabled=False;qClickPlus[pn];text<>"\n\nAnswer \!\(\* StyleBox[\"Incorrect\",\nFontColor->RGBColor[1, 0, 0]]\)", True, text<>"\n\nAnswer ?"] ]; answers=qPanelAnswers3[vars]; checks = {Checkbox[Dynamic[A1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[B1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[C1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[D1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[E1],Enabled->Dynamic[myEnabled]]}; (* Shuffle the answer keys *) index = RandomSample[Range[Length[answers]]]; answersShuffled = Table[answers[[index[[i]]]], {i, 1,Length[answers]}]; checksShuffled = Table[checks[[index[[i]]]], {i, 1,Length[answers]}]; body = { (* First row/colum the answer key *) {"A","B","C","D","E"}, (* First row/colum the proposed answers key *) answersShuffled, (* First row/colum the answer check boxes*) checksShuffled }; (* Kludge: answerStudent has problem with <>, so concatenated earlier*) Deploy[ Style[Panel[Grid[Transpose[body],Alignment->Left],Column[{answerStudent,qPanelEXPR3[vars]}],ImageMargins->10]]], {{xxx,1,""}, (* initial value of xxx, xxx=RandomReal[0.5] has to be in the button or else the test would not repeat*) Grid[{ {OpenerView[{Button["New Question",qTryAgain[pn];xxx=RandomReal[0.5];vars=qPanelTRYAGAIN3[];myEnabled=True;A1=False; B1=False;C1=False; D1= False; E1= False], "Try again"}], OpenerView[{Button["Hint",qTryAgain[pn];stateH=Not[stateH]],qPaneHint3[vars]},stateH], OpenerView[{Button["Solution",qTryAgain[pn];state=Not[state]],qPanelsolution3[vars,answerNum]},state]} ,{Null,Null,Null}}] &}, TrackedSymbols->Manipulate, SaveDefinitions->True,AppearanceElements->None,Initialization:>(qClicks = {{1, 0, 0, ""}, {2, 0, 0, ""}, {3, 0, 0, ""}, {4, 0, 0, ""}, {5, 0, 0, ""}, {6, 0, 0, ""},{7, 0, 0, ""},{8, 0, 0, ""},{9, 0, 0, ""},{10, 0, 0, ""}})] (*Manipulate*) , DynamicBoxOptions -> {BaseStyle -> Magnification -> qMagnification}] , (* Else if actual test *) Style[Manipulate[ vars=qPanelTRYAGAIN1[]; text=qPanelVariation1[pn,vars]; answer="?"; answerStudent=Dynamic[Which [A1,myEnabled=False;qClickPlus[pn];text<>"",C1,qClick[pn];qTryAgainNOT[pn];myEnabled=False;text<>"",B1,qClickPlus[pn];myEnabled=False;text<>"",D1, myEnabled=False;qClickPlus[pn];text<>"", True, text<>""]]; answers=qPanelAnswers1[vars]; checks = {Checkbox[Dynamic[A1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[B1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[C1],Enabled->Dynamic[myEnabled]],Checkbox[Dynamic[D1],Enabled->Dynamic[myEnabled]]}; (* Shuffle the answer keys *) index = RandomSample[Range[Length[answers]]]; answersShuffled = Table[answers[[index[[i]]]], {i, 1,Length[answers]}]; checksShuffled = Table[checks[[index[[i]]]], {i, 1,Length[answers]}]; body = { (* First row/colum the answer key *) {"A","B","C","D"}, (* First row/colum the proposed answers key *) answersShuffled, (* First row/colum the answer check boxes*) checksShuffled }; (* Kludge: answerStudent has problem with <>, so concatenated earlier*) Deploy[ Style[Panel[Grid[Transpose[body],Alignment->Left],Column[{answerStudent,qPanelEXPR1[vars]}],ImageMargins->10]]], "", TrackedSymbols->Manipulate, SaveDefinitions->True, AppearanceElements->None,SynchronousUpdating->False(*,Initialization:>(qClicks = {{1, 0, 0, ""}, {2, 0, 0, ""}, {3, 0, 0, ""}, {4, 0, 0, ""}, {5, 0, 0, ""}, {6, 0, 0, ""},{7, 0, 0, ""},{8, 0, 0, ""},{9, 0, 0, ""},{10, 0, 0, ""}})*)] (*Manipulate*) , DynamicBoxOptions -> {BaseStyle -> Magnification -> qMagnification}] ] ] End[]; EndPackage[];