WeBWorK Main Forum

mini selection algorithm perl

mini selection algorithm perl

by Zak Zarychta -
Number of replies: 1
I'm scratching my head wondering how to construct a selection algorithm in order that a correct logical connective is selected from an array given a random selection of a statement. I'm wondering if anybody may have already considered this.

Given the statements P,Q and logical connectives =>,<= arranged (for example, but not exclusively) in an array as the elements

[0] =>
[1] P
[2] Q
[3] <=

and if, P => Q. How might one select the correct logical connective given a random selection of either P or Q.

The basic idea is that i first want to randomly select a statement P or Q followed by an answer box and the other statement Q or P so that the correct logical connective is selected for comparison with the answer that the student gives.

P => Q or Q <= P

Any suggestions are welcome,
Zak

In reply to Zak Zarychta

Re: mini selection algorithm perl

by Zak Zarychta -
Having thought about it and slept on it

@ques=('P','Q','=>','<=')
$a=rand(0,1,1)
$b=abs($a-1)

BEGIN_TEXT
ques[$a] ques[$a+2] ques[$b]
END_TEXT