Hi,

First, Il love using this plugin which makes me improve my courses and I thank the ones who maintain this great plugin.

My problem is the following :

I want to define a random length list.

Hi,

First, Il love using this plugin which makes me improve my courses and I thank the ones who maintain this great plugin.

My problem is the following :

I want to define a random length list.

Example :

valeur = {5:10};

liste = fill(valeur,0);

The last line of the code generate an error.

Is there an other way to do this code ?

Vincent (France)

Bonjour Vincent,

As stated in the documentation (**↗**), the size of the list can only be a number, not an expression.

By the way, if you want numbers from 5 to 10, you must declare as a random variable:

value = {5:11};

because the last value is never included.

You can do operations in a loop with a variable number of values. For example, if you wanted to add the first n integers where n is chosen randomly, you would simply do:

Random variables

n = {1:11};

Global variables

s = 0; for (i: [1:11]) { s = i <= n? s + i: s; };

where s is the sum of the first n integers.

If you want to create a list where the number of elements is variable, for example a list of the sum of the first integers up to the sum of the first n integers, you would do:

list = fill(11,0); s = 0;> for (i:[1:11]) { s = i<=n ? s + i: s; j = i-1; list[j] = i<=n ? s: 0; };

The list always has 10 items, but only the first n have the desired value. The other elements remain with the value of 0.

It is therefore not a list of variable dimension but rather a list of pseudo variable dimension. I will be interested to know if this suits you.

You will find a very simple example (**↗**) that I prepared especially for you and one that I had already prepared before (**↗**).

Thank you, Dominique, for the prompt reply.

You'll think I'm very demanding with you.

Your solution is the situation I have for now. But is it possible to truncate the list after the last non zero value ?

You'll think I'm very demanding with you.

Your solution is the situation I have for now. But is it possible to truncate the list after the last non zero value ?

In the following example, I would like the students to give the list without the last non zero value because they are non significant.

Vincent

Vincent,

You can create a list of truly variable dimension, i.e. the dimension of the list actually varies, for example with the following code, which you would will also find **here ↗** and attached.

# Create pseudo variable size list list = fill(10,0); s = 0 ; for (i: [1:11]) { s = i<=n ? s + i : s ; j = i-1; list[j] = i<=n ? s : 0 ; }; # Create true variable size list size= pick(n-1,1,2,3,4,5,6,7,8,9,10); slist = fill(size,0); for (i: [0:10]) { j = i<n ? i : j ; slist[j] = list[j] ; };

However, if I understood your problem correctly, it is the number of answer boxes that you want to vary. In this case, a variable dimension list is of no help since you must specify one placeholder for each answer box and the number of placeholders is not variable. A workaround would be to identify the number of answer boxes that you want to keep displayed and hide the ones that are not required. You must also provide the default answer "0" for these boxes. This can be done easily with a little JavaScript script. Do not hesitate to ask for further explanation, or help if you need it, on the latter subject.

On the last subject, you might want to take a look at **this post ↗**.

Just impressive !

It is exactly what I was looking for. I would never have found this knack by myself !

This plugin is amazing and you too !

Once again, thank you dear Dominique.

Vincent

It is exactly what I was looking for. I would never have found this knack by myself !

This plugin is amazing and you too !

Once again, thank you dear Dominique.

Vincent