How To:
Deal With Unordered Lists

The Mathematical Formula type answer allows unordered lists of answers. Unfortunately it requires answers separated by semi-colons. Our authors prefer commas.

To do this you need a Maple graded question.

Suppose then you have 3 solutions: $a1, $a2 and $a3. Put these in the Answer field:

Now in the Maple graded box put the following code:

mark:= 0;
res:= [$RESPONSE];
ans:= [$ANSWER];
den:= convert(nops(ans),int);
totresponse:= convert(nops(res),int);
deduct:= max(totresponse-den,0);
i:=1;
while not (nops(res) = 0) do
        if i> nops(ans) then
                res:= subsop(1=NULL, res);
                i:= 1;
        elif res[1] = ans[i] then
                mark:= mark+1;
                res:= subsop(1=NULL,res);
                ans:= subsop(i=NULL,ans);
                i:=1;
        else
                i:= i+1;
        end if;
end do;
evalf((mark-deduct)/den);
Notes:
  1. You MUST change the "Expression Type" to Maple Syntax! - see the screen shot above.
  2. Duplicates are NOT treated as one, i.e. if the Answer field has 1,2,2 then the user must enter 1,2,2 for full marks.
  3. The grading code assigns part marks. For example if you get 2 of 3 right, or only enter 2 correct answers, your mark will be 67%. Each extra answer will reduce the possible mark. For example if you enter 1,2,3,4 when the answer is 1,2,3 you will recieve 67% also.

This code will deal with any fixed length of list. If your list length may vary you need to use the following very clever fix.

Varying Length Lists

Suppose, for example, your list may have 3 or 4 elements. Define your variables so the (possibly) missing value is always the last one. So calling our variables $ai, we will always have $a1, $a2 and $a3 but we may be missing $a4 . In the algorithmic section define the first three variables as usual and define the fourth one with a different name, say $Prea4 . Also define a flag that tells you whether $a4 will exist or not. In my example my variables and flag ($Isa4) are defined simply, obviously in real work your definitions mean something:

$a1=1;
$a2=2;
$a3=3;
$Prea4=4;
: If Isa4 = 0 there is no a4 ;
$Isa4=rint(3);
$Comma3=if(eq($Isa4,0),"",",");
$a4=if(eq($Isa4,0),"",$Prea4);

Notice that if the flag is off ($Isa4=0) then both $Comma3 and $a4 are empty strings. Then in your Answer field in the Maple grading section put:

$a1,$a2,$a3$Comma3$a4

This is brilliant, if $a4 exists the list is normal: $a1,$a2,$a3,$a4 , otherwise the list is truncated: $a1,$a2,$a3 . The Maple grading works fine with either.


How-To Index

Main Index

Last updated: 11/05/2018 SS/MUO