Overview of algorithmic exercises

Algorithmic exercises are simply exercises with random components. They are typically used so that students can not copy each others work because each student gets a different set of values within an exercise. MyStatCourse has a number of algorithmic exercises available to instructors under the Contributed section of the exercise database. Instructors can also create their own algorithmic exercises using the technique described below.

The Random URL

When creating an exercise, an instructor can specify a Web address for the random URL field. The Web location specified generates the desired random inputs for the exercise. MyStatCourse expects the Web location to return a URL encoded string containing the random values. URL encoding a string defines variables and concatenates them together using the & character. For example, a URL encoded string like

data=1+2+3&n=3&mean=2
defines three variables: data which is equal to "1 2 3" (note that the space is replaced with a + sign in the URL encoded string), n which is equal to 3 and mean which is equal to 2. Most programming platforms have ready-made routines for doing URL encoding.

For multipart exercises, it is best to define the random URL in the problem header and leave the field blank for subsequent parts. The random data will be handed down from the header to each part. If a random URL is defined for a part, the resulting random data will be appended to that from the header.

The first time a student loads an exercise with a random URL, MyStatCourse fetches the random data from the Web address and stores it for the student. Each time the student reloads the exercise they will see the same values as will an instructor who reviews the student’s work. When creating an assignment, the instructor will see different random data each time the assignment is loaded.

Inserting random values in exercise fields

The variables defined in the string returned from the random URL, can be inserted in exercise fields by placing the name of the variable inside curly brackets. For example, the screen shot below shows how one can construct a basic fill in the blank exercise using the URL encoded string defined above.

The above inputs will produce output like that shown below. Not that in this case, the random data values are displayed within StatCrunch.

For multiple choice exercises there is an additional field named random data correct which can be used to define the correct answer if a random URL is present. In this case, the random URL is often times used to shuffle options with the correct answer appearing in different locations within the ordering of options. The random data correct field should be set to a variable which evaluates to a, b, c, d or e with these values corresponding to the first, second, third, fourth or fifth option being correct.

Writing the code for random URL

The code for the random URL can be developed in any language. Scripting languages like PHP or PERL are natural choices. These scripting languages may even make calls to higher level programming languages like R. The code for the random URL in the above example is written in PHP as shown below:

 
<?php 
include("prob.php"); 
include("stat.php"); 
if(!$_GET["n"]) 
  $n = 3; 
else 
  $n = $_GET["n"]; 
$data = array(); 
while(count($data) < $n) 
  $data[] = round(10 + 1*normalRand(),2); 
$mean = round(mean($data),5); 
echo("data=".urlencode(implode($data," "))."&n=".urlencode($n)."&mean=".urlencode($mean)); 
?>

Note that this code uses two libraries, prob.php and stat.php, which are available here.

For the good of the order

Please keep in mind that when including a random URL in an exercise you will be relying on the URL actually being available. Be careful using random URLs which point to web servers beyond your control. If the URL is removed or the server goes down, your exercise will not load properly for students.

Please feel free to submit the code for your random URL to MyStatCourse if you are interested in sharing your algorithmic exercise with other instructors.