WeBWorK Problems

How to remove repeated entries from a list

Re: How to remove repeated entries from a list

by Tim Alderson -
Number of replies: 0
Update: I also found ``grep" to be useful:

$radio=new_multiple_choice();
$radio->qa(" ", "\( $L3[$a] \)$BR");

#the following removes the correct answer from the array L3
@L3 = grep { $_ != $L3[$a] } @L3; 

# Now L3 has only 4 entries. These are the remaining choices.
$radio->extra ("\(\displaystyle $L3[0]\) $BR", "\(\displaystyle $L3[1] \)$BR", "\(\displaystyle $L3[2] \)$BR","\(\displaystyle $L3[3]\)$BR");

#And for good measure...
$radio->makeLast("None of the above.");