Formulas question type fro Moodle 2.0

Re: Formulas question type fro Moodle 2.0

by Mithil Sharma -
Number of replies: 9

Hi Jean

Stumped again... how do I get it for 4 answer boxes? The below code works for {_0} and {_1}, but fails at {_3} and {_4}:

==============================

sol1 =[anz1,anz2,anz3,anz4];
sol2 =[anz2,anz1,anz3,anz4];
sol3 =[anz1,anz2,anz4,anz3];
sol4 =[anz2,anz1,anz4,anz3];
case1 = pick(1,diff(_r,sol1))==0 && pick(2,diff(_r,sol1))==0;
case2 = pick(1,diff(_r,sol2))==0 && pick(2,diff(_r,sol2))==0;
case3 = pick(3,diff(_r,sol3))==0 && pick(4,diff(_r,sol3))==0;
case4 = pick(3,diff(_r,sol4))==0 && pick(4,diff(_r,sol4))==0;

==============================

Thanks and Regards

Mithil

In reply to Mithil Sharma

Re: Formulas question type fro Moodle 2.0

by Mithil Sharma -

Hi Jean-Pierre,

Is there any way to have a variable element selected which has NOT been selected earlier from a variable list.

e.g. if U = {"John","Jack","Daniel","Alex"};

and if I write:

1) My name is {U}.

2) Your name is {any element of U, but not above element 1}

3) His name is {any element of U, but not element 1 or element 2 }


e.g. If it shows as

1) My name is Alex


Then 2) should show either

2a) Your name is John

2b) Your name is Jack

2b) Your name is Daniel

BUT NOT Your name is Alex


Going further, if 2) selects Your name is John

The 3) should show either

3a) His name is Jack

3b) His name is Daniel

BUT NOT His name is Alex, OR His name is John.


Basically, I want the variable list to reduce by THE one element which has been used earlier.

I am trying this with numbers, so, in the range from 1:5, If A=2, then B can be either 1 OR 3 OR 4 OR 5, but not 2.


Your help would be highly appreciated.

Thanks and Regards

Mithil

In reply to Mithil Sharma

Re: Formulas question type fro Moodle 2.0

by Thomas Killoran -

I tried the following, but then pick didn't do what it was supposed to:

Random:  n={0:3};

Global:

A=pick(n,["Tom","Dick","Harry","George"]);

n1=n+1;

B=pick(n1,["Tom","Dick","Harry","George"]);

n2=n==3?1:n+2;

C=pick(n2,["Tom","Dick","Harry","George"]);


It kept giving me wrong selections.  For instance:

Tom  n=3 (should have been George)

Dick  n1=4 (Should have been Tom)

Dick n2=1  (Should have been Dick)


This is the first time that pick has failed me.

From the description it should work:

pick(i,X) 
pick(i,x0,x1,...) 
pick(1<2,["A","B"]) 
"B" 
pick(10,"","A","B") 
"" 
pick(1,[1,2],[3,4]) 
[3,4] 
A safe variant of list subscript. It will pick the i-th element from the list X or the first element if index out of range. 
pick(i,x0,x1,...) will pick the i-th element in the [x0,x1,...] , or x0 if index out of range.


I removed the [  ] and it worked until n=4, then it would leave that one blank instead of picking the first element.

In reply to Thomas Killoran

Re: Formulas question type fro Moodle 2.0

by Bernat Martinez -

In my opinion  pick doesn't fail,  according your set up  n takes the values 0,1,2, to take the 4 values you have to write

Random:  n={0:4};  take  values 0,1,2,3

In reply to Bernat Martinez

Re: Formulas question type fro Moodle 2.0

by Thomas Killoran -

It is my limited understanding that the following code should produce 5, but I get zero back.


A=pick(5,[0,1,2,3,4,5,6]);

In reply to Thomas Killoran

Re: Formulas question type fro Moodle 2.0

by Bernat Martinez -

Take into account that you are picking from a list composed of one element,

A=pick(5,0,1,2,3,4,5,6); => A=5


In reply to Mithil Sharma

Re: Formulas question type fro Moodle 2.0

by Jean-Michel Védrine -

Hello Mithil

I am not sure I understand correctly what you want but you could try this:

Random variables:

 F=shuffle(["John", "Jack", "Daniel", "Alex"]);

Global variables:

A =F[0];

B= F[1];

C= F[2];

Then A B and C will all contain a different firstname

So then in the question text if you write

1) My name is {=A}.

2) Your name is {=B}

3) His name is {=C}

You will get something like

1) My name is Jack.

2) Your name is Alex

3) His name is Daniel

Explanation

  F=shuffle(["John", "Jack", "Daniel", "Alex"]);

will put a permutation of the list ["John", "Jack", "Daniel", "Alex"] in variable F ( for instance["Jack", "Alex", "Daniel", "John"])

Then when we do something like A =F[0]; we will get the first element of the list F, Jack in our example

B= F[1]; will give us the second element of list F (Alex in our example)

C= F[2]; will give us the third element of listF (that is Daniel in our example)


In reply to Jean-Michel Védrine

Re: Formulas question type fro Moodle 2.0

by Mithil Sharma -

You hit the nail on the head - that's exactly what I wanted.

Thanks a lot!!

Mithil

In reply to Jean-Michel Védrine

Re: Formulas question type fro Moodle 2.0

by Mithil Sharma -

Hi Jean

One more here:

How can I get a random list which can be shuffled?

e.g.:

A=5;

B=7;

C=3;

F=shuffle(5 numbers between 1 and 9, 7 numbers between 11 to 19, 3 numbers between 21 to 29);

Here, 5 numbers, 7 numbers and 3 numbers equate to variable A, B and C.


The resultant list could be something like this:

F = shuffle(2,1,2,3,5, #i.e. 5 numbers between 1 and 9

11,15,12,12,16,14,18, #i.e. 7 numbers between 11 and 19

22,26,23 #i.e. 3 numbers between 21 and 30);