# AnswerOrderedList1

Jump to: navigation, search

## Answer is an Ordered List

This PG code shows how to write a question in which the answer is an ordered list, such as a sequence of numbers.

PG problem file Explanation

Problem tagging:

```DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
);

TEXT(beginproblem());
```

Initialization:

```Context("Numeric");

@seq = ();
\$seq = 1;
\$seq = 1;
foreach my \$i (2..6) {
\$seq[\$i] = \$seq[\$i-1] + \$seq[\$i-2];
}

\$answer = join(", ",@seq);
\$answer = Compute("\$answer");
```

Setup: We create an empty array `@seq` and then fill it with scalars using direct assignment and a foreach loop. Since the entries in the array `@seq` do not have commas between them, we create a Perl string `\$answer` that joins the entries of the array `@seq` by a comma followed by a space `", "`. Then, we make this string a MathObject by putting `Compute()` around it.

```Context()->texStrings;
BEGIN_TEXT
If \( s_1 = \$seq \), \( s_2 = \$seq \), and
\( s_n = s_{n-1} + s_{n-2} \), find the first seven
terms of this sequence, including \( s_1 \) and
\( s_2 \).  Enter your answer as a comma separated
list of numbers.
\$BR
\$BR
Sequence = \{ ans_rule(40) \}
\{ AnswerFormatHelp("numbers") \}
END_TEXT
Context()->normalStrings;
```

Main Text:

```\$showPartialCorrectAnswers=1;

ANS( \$answer->cmp(ordered=>1) );
```

Answer Evaluation: Since the answer is a MathObject List, which is by default unordered, we must specify that the answer checker use `ordered=>1`

```Context()->texStrings;
BEGIN_SOLUTION
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();
```

Solution: