DOCUMENT();

loadMacros(
    'PGstandard.pl', 'PGML.pl', 'parserPopUp.pl', 'PGgraders.pl',
    'PGcourse.pl'
);

$showPartialCorrectAnswers = 0;

# Incremental grader
install_problem_grader(~~&custom_problem_grader_fluid);
$ENV{grader_numright} = [ 2,   4,   6 ];
$ENV{grader_scores}   = [ 0.3, 0.6, 1 ];
$ENV{grader_message} =
    'You can earn '
    . '30% partial credit for 2 - 3 correct answers, and '
    . '60% partial credit for 4 - 5 correct answers.';

# All or nothing grader
# install_problem_grader(~~&std_problem_grader);

# Create a list of questions and answers.
@q_and_a = (
    [ 'Question a?', 'Answer a' ],
    [ 'Question b?', 'Answer b' ],
    [ 'Question c?', 'Answer c' ],
    [ 'Question d?', 'Answer d' ],
    [ 'Question e?', 'Answer e' ],
    [ 'Question f?', 'Answer f' ],
);

# Add extra incorrect answers
@extra_a = ('Extra answer 1', 'Extra answer 2');

# Randomize the questions.
@q_and_a = map { splice(@q_and_a, random(0, $#q_and_a)) } 0 .. $#q_and_a;

# Choose a random order to display the answers (including the incorrect answers).
push(@answers, (map { $_->[1] } @q_and_a), @extra_a);
@indices = (0 .. $#answers);
@shuffle = map { splice(@indices, random(0, $#indices), 1) } 0 .. $#indices;

# Create an inverse map back to the original indices.
@inversion[@shuffle] = (0 .. $#shuffle);

# Add an answer that is always last.  It is also incorrect in this case.
push(@answers, 'None of the above');
push(@shuffle, scalar(@shuffle));

@answer_dropdowns =
    map { DropDown([ @ALPHABET[ 0 .. $#answers ] ], $inversion[$_]) }
    0 .. $#q_and_a;

HEADER_TEXT(MODES(TeX => '', HTML => <<END_STYLE));
<style>
.two-column {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    align-items: center;
    justify-content: space-evenly;
}
</style>
END_STYLE

BEGIN_PGML
Match each question with its answer.

[<
    [<
        [@ join(
            "\n\n",
            map {
                '[_]{$answer_dropdowns[' . $_ . ']} '
                    . '*' . ($_ + 1) . '.* '
                    . '[$q_and_a[' . $_ . '][0]]'
            } 0 .. $#q_and_a
        ) @]**
    >]{ [ 'div' ] }{ [ '\\parbox{0.55\\linewidth}{', '}' ] }
    [@ MODES(TeX => '\\hfill', HTML => '') @]*
    [<
        [@ join(
            "\n\n",
            map {
                '*' . $ALPHABET[($_)] . '.* [$answers[$shuffle[' . $_ . ']]]'
            } 0 .. $#answers
        ) @]**
    >]{ [ 'div' ] }{ [ '\\parbox{0.25\\linewidth}{', '}' ] }
>]{ [ 'div', class => 'two-column' ] }
END_PGML

BEGIN_PGML_SOLUTION
The correct answers are
[@ join(', ', map { $ALPHABET[($inversion[($_)])] } 0 .. $#q_and_a) @]*.
END_PGML_SOLUTION

ENDDOCUMENT();