%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SETUP
\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{calc}
\usepackage{ifthen}
\usepackage{color}
\usepackage{graphicx}
\usepackage{tikz}
\oddsidemargin=0.55in
\evensidemargin=0.55in
\textwidth=5.5in
\topmargin=-0.5in
\textheight=9.25in
\parindent=0in
\pagestyle{empty}
\reversemarginpar
\def\vs{\vspace{.85\baselineskip}}
\def\svs{\vspace{.5\baselineskip}}
\def\nvs{\vspace{-.85\baselineskip}}
\def\nsvs{\vspace{-.5\baselineskip}}
\def\vf{\vfill}
\def\ds{\displaystyle}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% COUNTERS
% problem counter
\newcounter{probcounter}
\setcounter{probcounter}{0}
% subproblem counter
\newcounter{subprobcounter}
\setcounter{subprobcounter}{0}
\renewcommand{\thesubprobcounter}{\alph{subprobcounter}}
% MCpart counter
\newcounter{MCpartcounter}
\setcounter{MCpartcounter}{0}
% MCanswer
\newcounter{MCanswer}
\setcounter{MCanswer}{0}
% holder for the first answer
\newcounter{firstanswer}
\setcounter{firstanswer}{0}
% holder for the second answer
\newcounter{secondanswer}
\setcounter{secondanswer}{0}
% holder for the third answer
\newcounter{thirdanswer}
\setcounter{thirdanswer}{0}
% holder to identify the first problem
\newcounter{randone}
\setcounter{randone}{0}
% holder to identify the second problem
\newcounter{randtwo}
\setcounter{randtwo}{0}
% holder to identify the third problem
\newcounter{randthree}
\setcounter{randthree}{0}
% difficulty for each problem
\newcounter{difficulty}
\setcounter{difficulty}{0}
% total difficulty of quiz
\newcounter{quizlevel}
\setcounter{quizlevel}{0}
% how many questions from first quiz are repeated on random quiz
\newcounter{first}
\setcounter{first}{0}
% final code is calculated after answers have been set
% see end of Mastery Quiz generation code block
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PROBLEMS AND ANSWERS
\pgfmathsetseed{\number\pdfrandomseed} % resets pgfmath seed
\newcommand{\randomproblem}{
\pgfmathrandom{\banksize}
% questions from first quiz
\ifnum\pgfmathresult=1 \firstA \addtocounter{difficulty}{\firstAdiff}
\addtocounter{first}{1} \fi
\ifnum\pgfmathresult=2 \firstB \addtocounter{difficulty}{\firstBdiff}
\addtocounter{first}{1} \fi
\ifnum\pgfmathresult=3 \firstC \addtocounter{difficulty}{\firstCdiff}
\addtocounter{first}{1} \fi
% questions from test bank
\ifnum\pgfmathresult=4 \AAA \addtocounter{difficulty}{\AAAdiff} \fi
\ifnum\pgfmathresult=5 \BBB \addtocounter{difficulty}{\BBBdiff} \fi
\ifnum\pgfmathresult=6 \CCC \addtocounter{difficulty}{\CCCdiff} \fi
\ifnum\pgfmathresult=7 \DDD \addtocounter{difficulty}{\DDDdiff} \fi
\ifnum\pgfmathresult=8 \EEE \addtocounter{difficulty}{\EEEdiff} \fi
\ifnum\pgfmathresult=9 \FFF \addtocounter{difficulty}{\FFFdiff} \fi
\par
}
\newcommand{\displayproblem}[2]{
\hspace{-.4pc}{\bf\em #1} \\[.5pc] #2}
% collect the ANSWER
% will be used to generate the version number for the quiz
% and make it visible *IF* user has defined \ShowAnswers to be "yes"
\ifthenelse
{\equal{\ShowAnswers}{yes}}
{\def\ANSWER{\setcounter{MCanswer}{\theMCpartcounter}\textcolor{red}{\bf\Large *}}}
{\def\ANSWER{\setcounter{MCanswer}{\theMCpartcounter}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PROBLEM FORMATTING
% problem environment
\newcommand{\prob}[1]
{\phantom{x}\hspace{-.25in}
\setcounter{subprobcounter}{0}
\setcounter{MCpartcounter}{0}
\refstepcounter{probcounter}
{\large \bf \theprobcounter.} $\;$
\parbox[t]{5.65in}{#1} \\[1pc]}
% subproblem environment
\newcommand{\subprob}[1]
{\refstepcounter{subprobcounter}
\hspace{.25in}
{\bf \thesubprobcounter)} $\;$
\parbox[t]{5.35in}{#1}
\svs}
% unlabeled subitem environment
\newcommand{\thing}[1]
{\hspace{.25in}
\parbox[t]{5.35in}{#1}
\vs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% MULTIPLE CHOICE ORDERING FOR ONE-PER-LINE ITEMS
% don't laugh, it works
% MC options one on each line
\newcommand{\MCone}[4]
{\phantom{x}\hspace{.07in}
\begin{tabular}{p{5.25in}}
% part A
\refstepcounter{MCpartcounter} \\*[-1pc]%hack to kill refstep space
{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 first
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{1243}\or\equal{\MCorder}{1324}
\or\equal{\MCorder}{1342}\or\equal{\MCorder}{1423}\or\equal{\MCorder}{1432}}
{#1}
{}%
% put in second item if MCorder has 2 first
\ifthenelse
{\equal{\MCorder}{2134}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{2314}
\or\equal{\MCorder}{2341}\or\equal{\MCorder}{2413}\or\equal{\MCorder}{2431}}
{#2}
{}%
% put in third item if MCorder has 3 first
\ifthenelse
{\equal{\MCorder}{3124}\or\equal{\MCorder}{3142}\or\equal{\MCorder}{3214}
\or\equal{\MCorder}{3241}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{3421}}
{#3}
{}%
% put in fourth item if MCorder has 4 first
\ifthenelse
{\equal{\MCorder}{4123}\or\equal{\MCorder}{4132}\or\equal{\MCorder}{4213}
\or\equal{\MCorder}{4231}\or\equal{\MCorder}{4312}\or\equal{\MCorder}{4321}}
{#4}
{} \\
% part B
\refstepcounter{MCpartcounter}
{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 second
\ifthenelse
{\equal{\MCorder}{2134}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{3124}
\or\equal{\MCorder}{3142}\or\equal{\MCorder}{4123}\or\equal{\MCorder}{4132}}
{#1}
{}%
% put in second item if MCorder has 2 second
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{1243}\or\equal{\MCorder}{3214}
\or\equal{\MCorder}{3241}\or\equal{\MCorder}{4213}\or\equal{\MCorder}{4231}}
{#2}
{}%
% put in third item if MCorder has 3 second
\ifthenelse
{\equal{\MCorder}{1324}\or\equal{\MCorder}{1342}\or\equal{\MCorder}{2314}
\or\equal{\MCorder}{2341}\or\equal{\MCorder}{4312}\or\equal{\MCorder}{4321}}
{#3}
{}%
% put in fourth item if MCorder has 4 second
\ifthenelse
{\equal{\MCorder}{1423}\or\equal{\MCorder}{1432}\or\equal{\MCorder}{2413}
\or\equal{\MCorder}{2431}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{3421}}
{#4}
{} \\
% part C
\refstepcounter{MCpartcounter}
{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 third
\ifthenelse
{\equal{\MCorder}{2314}\or\equal{\MCorder}{3214}\or\equal{\MCorder}{2413}
\or\equal{\MCorder}{4213}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{4312}}
{#1}
{}%
% put in second item if MCorder has 2 third
\ifthenelse
{\equal{\MCorder}{1324}\or\equal{\MCorder}{3124}\or\equal{\MCorder}{1423}
\or\equal{\MCorder}{4123}\or\equal{\MCorder}{3421}\or\equal{\MCorder}{4321}}
{#2}
{}%
% put in third item if MCorder has 3 third
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{2134}\or\equal{\MCorder}{1432}
\or\equal{\MCorder}{4132}\or\equal{\MCorder}{2431}\or\equal{\MCorder}{4231}}
{#3}
{}%
% put in fourth item if MCorder has 4 third
\ifthenelse
{\equal{\MCorder}{1243}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{1342}
\or\equal{\MCorder}{3142}\or\equal{\MCorder}{2341}\or\equal{\MCorder}{3241}}
{#4}
{} \\
% part D
\refstepcounter{MCpartcounter}
{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 fourth
\ifthenelse
{\equal{\MCorder}{2341}\or\equal{\MCorder}{3241}\or\equal{\MCorder}{2431}
\or\equal{\MCorder}{4231}\or\equal{\MCorder}{3421}\or\equal{\MCorder}{4321}}
{#1}
{}%
% put in second item if MCorder has 2 fourth
\ifthenelse
{\equal{\MCorder}{1342}\or\equal{\MCorder}{3142}\or\equal{\MCorder}{1432}
\or\equal{\MCorder}{4132}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{4312}}
{#2}
{}%
% put in third item if MCorder has 3 fourth
\ifthenelse
{\equal{\MCorder}{1243}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{1423}
\or\equal{\MCorder}{4123}\or\equal{\MCorder}{2413}\or\equal{\MCorder}{4213}}
{#3}
{}%
% put in fourth item if MCorder has 4 fourth
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{2134}\or\equal{\MCorder}{1324}
\or\equal{\MCorder}{3124}\or\equal{\MCorder}{2314}\or\equal{\MCorder}{3214}}
{#4}
{}
\end{tabular}
\vs\svs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% MULTIPLE CHOICE ORDERING FOR TWO-PER-LINE ITEMS
% stop laughing
% MC options two on each line
\newcommand{\MCtwo}[4]
{\phantom{x}\hspace{.07in}
\begin{tabular}{p{2.57in}p{2.57in}}
% part A
\refstepcounter{MCpartcounter} \\*[-1pc]%hack to kill refstep space
{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 first
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{1243}\or\equal{\MCorder}{1324}
\or\equal{\MCorder}{1342}\or\equal{\MCorder}{1423}\or\equal{\MCorder}{1432}}
{#1}
{}%
% put in second item if MCorder has 2 first
\ifthenelse
{\equal{\MCorder}{2134}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{2314}
\or\equal{\MCorder}{2341}\or\equal{\MCorder}{2413}\or\equal{\MCorder}{2431}}
{#2}
{}%
% put in third item if MCorder has 3 first
\ifthenelse
{\equal{\MCorder}{3124}\or\equal{\MCorder}{3142}\or\equal{\MCorder}{3214}
\or\equal{\MCorder}{3241}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{3421}}
{#3}
{}%
% put in fourth item if MCorder has 4 first
\ifthenelse
{\equal{\MCorder}{4123}\or\equal{\MCorder}{4132}\or\equal{\MCorder}{4213}
\or\equal{\MCorder}{4231}\or\equal{\MCorder}{4312}\or\equal{\MCorder}{4321}}
{#4}
{}
% part B
\refstepcounter{MCpartcounter}
&{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 second
\ifthenelse
{\equal{\MCorder}{2134}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{3124}
\or\equal{\MCorder}{3142}\or\equal{\MCorder}{4123}\or\equal{\MCorder}{4132}}
{#1}
{}%
% put in second item if MCorder has 2 second
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{1243}\or\equal{\MCorder}{3214}
\or\equal{\MCorder}{3241}\or\equal{\MCorder}{4213}\or\equal{\MCorder}{4231}}
{#2}
{}%
% put in third item if MCorder has 3 second
\ifthenelse
{\equal{\MCorder}{1324}\or\equal{\MCorder}{1342}\or\equal{\MCorder}{2314}
\or\equal{\MCorder}{2341}\or\equal{\MCorder}{4312}\or\equal{\MCorder}{4321}}
{#3}
{}%
% put in fourth item if MCorder has 4 second
\ifthenelse
{\equal{\MCorder}{1423}\or\equal{\MCorder}{1432}\or\equal{\MCorder}{2413}
\or\equal{\MCorder}{2431}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{3421}}
{#4}
{} \\*[1pc]
% part C
\refstepcounter{MCpartcounter} \\*[-1pc]%hack to kill refstep space
{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 third
\ifthenelse
{\equal{\MCorder}{2314}\or\equal{\MCorder}{3214}\or\equal{\MCorder}{2413}
\or\equal{\MCorder}{4213}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{4312}}
{#1}
{}%
% put in second item if MCorder has 2 third
\ifthenelse
{\equal{\MCorder}{1324}\or\equal{\MCorder}{3124}\or\equal{\MCorder}{1423}
\or\equal{\MCorder}{4123}\or\equal{\MCorder}{3421}\or\equal{\MCorder}{4321}}
{#2}
{}%
% put in third item if MCorder has 3 third
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{2134}\or\equal{\MCorder}{1432}
\or\equal{\MCorder}{4132}\or\equal{\MCorder}{2431}\or\equal{\MCorder}{4231}}
{#3}
{}%
% put in fourth item if MCorder has 4 third
\ifthenelse
{\equal{\MCorder}{1243}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{1342}
\or\equal{\MCorder}{3142}\or\equal{\MCorder}{2341}\or\equal{\MCorder}{3241}}
{#4}
{}
% part D
\refstepcounter{MCpartcounter}
&{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 fourth
\ifthenelse
{\equal{\MCorder}{2341}\or\equal{\MCorder}{3241}\or\equal{\MCorder}{2431}
\or\equal{\MCorder}{4231}\or\equal{\MCorder}{3421}\or\equal{\MCorder}{4321}}
{#1}
{}%
% put in second item if MCorder has 2 fourth
\ifthenelse
{\equal{\MCorder}{1342}\or\equal{\MCorder}{3142}\or\equal{\MCorder}{1432}
\or\equal{\MCorder}{4132}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{4312}}
{#2}
{}%
% put in third item if MCorder has 3 fourth
\ifthenelse
{\equal{\MCorder}{1243}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{1423}
\or\equal{\MCorder}{4123}\or\equal{\MCorder}{2413}\or\equal{\MCorder}{4213}}
{#3}
{}%
% put in fourth item if MCorder has 4 fourth
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{2134}\or\equal{\MCorder}{1324}
\or\equal{\MCorder}{3124}\or\equal{\MCorder}{2314}\or\equal{\MCorder}{3214}}
{#4}
{}
\end{tabular}
\vs\svs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% MULTIPLE CHOICE ORDERING FOR FOUR-PER-LINE ITEMS
% yeah, yeah
% MC options four across
\newcommand{\MCfour}[4]
{\phantom{x}\hspace{.07in}
\begin{tabular}{p{1.2in}p{1.2in}p{1.2in}p{1.2in}}
% part A
\refstepcounter{MCpartcounter} \\*[-1pc]%hack to kill refstep space
{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 first
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{1243}\or\equal{\MCorder}{1324}
\or\equal{\MCorder}{1342}\or\equal{\MCorder}{1423}\or\equal{\MCorder}{1432}}
{#1}
{}%
% put in second item if MCorder has 2 first
\ifthenelse
{\equal{\MCorder}{2134}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{2314}
\or\equal{\MCorder}{2341}\or\equal{\MCorder}{2413}\or\equal{\MCorder}{2431}}
{#2}
{}%
% put in third item if MCorder has 3 first
\ifthenelse
{\equal{\MCorder}{3124}\or\equal{\MCorder}{3142}\or\equal{\MCorder}{3214}
\or\equal{\MCorder}{3241}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{3421}}
{#3}
{}%
% put in fourth item if MCorder has 4 first
\ifthenelse
{\equal{\MCorder}{4123}\or\equal{\MCorder}{4132}\or\equal{\MCorder}{4213}
\or\equal{\MCorder}{4231}\or\equal{\MCorder}{4312}\or\equal{\MCorder}{4321}}
{#4}
{}
% part B
\refstepcounter{MCpartcounter}
&{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 second
\ifthenelse
{\equal{\MCorder}{2134}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{3124}
\or\equal{\MCorder}{3142}\or\equal{\MCorder}{4123}\or\equal{\MCorder}{4132}}
{#1}
{}%
% put in second item if MCorder has 2 second
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{1243}\or\equal{\MCorder}{3214}
\or\equal{\MCorder}{3241}\or\equal{\MCorder}{4213}\or\equal{\MCorder}{4231}}
{#2}
{}%
% put in third item if MCorder has 3 second
\ifthenelse
{\equal{\MCorder}{1324}\or\equal{\MCorder}{1342}\or\equal{\MCorder}{2314}
\or\equal{\MCorder}{2341}\or\equal{\MCorder}{4312}\or\equal{\MCorder}{4321}}
{#3}
{}%
% put in fourth item if MCorder has 4 second
\ifthenelse
{\equal{\MCorder}{1423}\or\equal{\MCorder}{1432}\or\equal{\MCorder}{2413}
\or\equal{\MCorder}{2431}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{3421}}
{#4}
{}
% part C
\refstepcounter{MCpartcounter}
&{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 third
\ifthenelse
{\equal{\MCorder}{2314}\or\equal{\MCorder}{3214}\or\equal{\MCorder}{2413}
\or\equal{\MCorder}{4213}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{4312}}
{#1}
{}%
% put in second item if MCorder has 2 third
\ifthenelse
{\equal{\MCorder}{1324}\or\equal{\MCorder}{3124}\or\equal{\MCorder}{1423}
\or\equal{\MCorder}{4123}\or\equal{\MCorder}{3421}\or\equal{\MCorder}{4321}}
{#2}
{}%
% put in third item if MCorder has 3 third
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{2134}\or\equal{\MCorder}{1432}
\or\equal{\MCorder}{4132}\or\equal{\MCorder}{2431}\or\equal{\MCorder}{4231}}
{#3}
{}%
% put in fourth item if MCorder has 4 third
\ifthenelse
{\equal{\MCorder}{1243}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{1342}
\or\equal{\MCorder}{3142}\or\equal{\MCorder}{2341}\or\equal{\MCorder}{3241}}
{#4}
{}
% part D
\refstepcounter{MCpartcounter}
&{\bf \Alph{MCpartcounter})}\,
% put in first item if MCorder has 1 fourth
\ifthenelse
{\equal{\MCorder}{2341}\or\equal{\MCorder}{3241}\or\equal{\MCorder}{2431}
\or\equal{\MCorder}{4231}\or\equal{\MCorder}{3421}\or\equal{\MCorder}{4321}}
{#1}
{}%
% put in second item if MCorder has 2 fourth
\ifthenelse
{\equal{\MCorder}{1342}\or\equal{\MCorder}{3142}\or\equal{\MCorder}{1432}
\or\equal{\MCorder}{4132}\or\equal{\MCorder}{3412}\or\equal{\MCorder}{4312}}
{#2}
{}%
% put in third item if MCorder has 3 fourth
\ifthenelse
{\equal{\MCorder}{1243}\or\equal{\MCorder}{2143}\or\equal{\MCorder}{1423}
\or\equal{\MCorder}{4123}\or\equal{\MCorder}{2413}\or\equal{\MCorder}{4213}}
{#3}
{}%
% put in fourth item if MCorder has 4 fourth
\ifthenelse
{\equal{\MCorder}{1234}\or\equal{\MCorder}{2134}\or\equal{\MCorder}{1324}
\or\equal{\MCorder}{3124}\or\equal{\MCorder}{2314}\or\equal{\MCorder}{3214}}
{#4}
{}
\end{tabular}
\svs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% GENERATE MASTERY QUIZ
\begin{document}
{\Large \bf Mastery Quiz \SectionNumber}
\hfill {\bf Name:} \underline{\hspace{2in}}
\vs
{\bf \SectionName}
\vs
{\em You may not use books, notes, calculators, phones, or any outside resources. \\
Answer easier questions first, take your time, check your answers. You can do this!}
\vs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PRINT THE FIRST PROBLEM
% for first bank
% put in \firstA, \firstB, or \firstC depending on what digit is first in \ProblemOrder
\ifthenelse
{\equal{\QuizType}{first}}
{\ifthenelse{\equal{\ProblemOrder}{123}}{\firstA}{}
\ifthenelse{\equal{\ProblemOrder}{132}}{\firstA}{}
\ifthenelse{\equal{\ProblemOrder}{213}}{\firstB}{}
\ifthenelse{\equal{\ProblemOrder}{231}}{\firstB}{}
\ifthenelse{\equal{\ProblemOrder}{312}}{\firstC}{}
\ifthenelse{\equal{\ProblemOrder}{321}}{\firstC}}{}
{}
% for random bank
\ifthenelse
{\equal{\QuizType}{random}}
{\randomproblem
\setcounter{firstanswer}{\theMCanswer}
\setcounter{randone}{\pgfmathresult}}
{}
% for last bank
% put in \lastA, \lastB, or \lastC depending on what digit is first in \ProblemOrder
\ifthenelse
{\equal{\QuizType}{last}}
{\ifthenelse{\equal{\ProblemOrder}{123}}{\lastA}{}
\ifthenelse{\equal{\ProblemOrder}{132}}{\lastA}{}
\ifthenelse{\equal{\ProblemOrder}{213}}{\lastB}{}
\ifthenelse{\equal{\ProblemOrder}{231}}{\lastB}{}
\ifthenelse{\equal{\ProblemOrder}{312}}{\lastC}{}
\ifthenelse{\equal{\ProblemOrder}{321}}{\lastC}}{}
{}
\vf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PRINT THE SECOND PROBLEM
% for first bank
% put in \firstA, \firstB, or \firstC depending on what digit is second in \ProblemOrder
\ifthenelse
{\equal{\QuizType}{first}}
{\ifthenelse{\equal{\ProblemOrder}{123}}{\firstB}{}
\ifthenelse{\equal{\ProblemOrder}{132}}{\firstC}{}
\ifthenelse{\equal{\ProblemOrder}{213}}{\firstA}{}
\ifthenelse{\equal{\ProblemOrder}{231}}{\firstC}{}
\ifthenelse{\equal{\ProblemOrder}{312}}{\firstA}{}
\ifthenelse{\equal{\ProblemOrder}{321}}{\firstB}}{}
{}
% for random bank
\ifthenelse
{\equal{\QuizType}{random}}
{\randomproblem
\setcounter{secondanswer}{\theMCanswer}
\setcounter{randtwo}{\pgfmathresult}}
{}
% for last bank
% put in \lastA, \lastB, or \lastC depending on what digit is second in \ProblemOrder
\ifthenelse
{\equal{\QuizType}{last}}
{\ifthenelse{\equal{\ProblemOrder}{123}}{\lastB}{}
\ifthenelse{\equal{\ProblemOrder}{132}}{\lastC}{}
\ifthenelse{\equal{\ProblemOrder}{213}}{\lastA}{}
\ifthenelse{\equal{\ProblemOrder}{231}}{\lastC}{}
\ifthenelse{\equal{\ProblemOrder}{312}}{\lastA}{}
\ifthenelse{\equal{\ProblemOrder}{321}}{\lastB}}{}
{}
\vf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PRINT THE THIRD PROBLEM
% for first bank
% put in \firstA, \firstB, or \firstC depending on what digit is third in \ProblemOrder
\ifthenelse
{\equal{\QuizType}{first}}
{\ifthenelse{\equal{\ProblemOrder}{123}}{\firstC}{}
\ifthenelse{\equal{\ProblemOrder}{132}}{\firstB}{}
\ifthenelse{\equal{\ProblemOrder}{213}}{\firstC}{}
\ifthenelse{\equal{\ProblemOrder}{231}}{\firstA}{}
\ifthenelse{\equal{\ProblemOrder}{312}}{\firstB}{}
\ifthenelse{\equal{\ProblemOrder}{321}}{\firstA}}{}
{}
% for random bank
\ifthenelse
{\equal{\QuizType}{random}}
{\randomproblem
\setcounter{thirdanswer}{\theMCanswer}
\setcounter{randthree}{\pgfmathresult}}
{}
% for last bank
% put in \lastA, \lastB, or \lastC depending on what digit is first in \ProblemOrder
\ifthenelse
{\equal{\QuizType}{last}}
{\ifthenelse{\equal{\ProblemOrder}{123}}{\lastC}{}
\ifthenelse{\equal{\ProblemOrder}{132}}{\lastB}{}
\ifthenelse{\equal{\ProblemOrder}{213}}{\lastC}{}
\ifthenelse{\equal{\ProblemOrder}{231}}{\lastA}{}
\ifthenelse{\equal{\ProblemOrder}{312}}{\lastB}{}
\ifthenelse{\equal{\ProblemOrder}{321}}{\lastA}}{}
{}
\vf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PRINT A WARNING IF ANY PROBLEMS REPEATED
% only relevant for random bank quizzes
\ifthenelse
{\equal{\QuizType}{random}}
{\ifnum\therandone=\therandtwo {\Huge \bf REPEAT -- PLZ RECOMPILE} \fi
\ifnum\therandone=\therandthree {\Huge \bf REPEAT -- PLZ RECOMPILE} \fi
\ifnum\therandtwo=\therandthree {\Huge \bf REPEAT -- PLZ RECOMPILE} \fi}
{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CREATE THE CODE
% create a three-digit number corresponding to the answers, in order
\newcounter{tripledigit}
\setcounter{tripledigit}{100*\thefirstanswer+10*\thesecondanswer+\thethirdanswer}
% do something to the three-digit number
% MAKE THIS BETTER, THIS IS JUST A SAMPLE AND IS NOT SECURE
\newcounter{change}
\setcounter{change}{\thetripledigit*42}
% choose a random scalar from 1 to 9
\newcounter{scalar}
\pgfmathrandom{9}
\setcounter{scalar}{\pgfmathresult}
% multiply the scalar times the changed number
\newcounter{product}
\setcounter{product}{\thescalar*\thechange}
% red herring number
\newcounter{redherring}
\pgfmathrandom{9}
\setcounter{redherring}{\pgfmathresult}
%%%%% CODE SOLUTION
% final code: append counters in some way to make one numerical code
% MAKE THIS BETTER, THIS IS JUST A SAMPLE AND IS NOT SECURE
\newcounter{answercode}
\setcounter{answercode}{100*\theredherring+10*\thechange+1*\thescalar}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PRINT VERSION NUMBER
% print the version number if the quiz is from the random bank
\ifthenelse
{\equal{\QuizType}{random}}
{\nvs\phantom{x}\hfill \small{\em Version \theanswercode - FIX THIS CODE BEFORE USING}}
{}
\svs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PRINT HOMEWORK LIST
\ifthenelse
{\equal{\QuizType}{last}}
% don't print HW if final exam / last quiz
{}
% else print divider line and homework
{\hrule
\svs
{\bf \small \textcolor{gray}{Based on~\SectionNumber~Homework}} \\
{\small \textcolor{gray}{\Homework}}}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% END THE DOCUMENT unless the full bank is to be printed
\ifthenelse
{\equal{\PrintTestBank}{yes}}
{}
{\end{document}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TEST PRINT ALL PROBLEMS
{\large \bf MATH 231, Section \SectionNumber:~\SectionName} \\[.25pc]
{\large \bf TEST PRINT OF ALL PROBLEMS}
\vs\vs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\large \bf First-time quiz}
\vs
\hrule
\vs
\setcounter{probcounter}{0}
\displayproblem{firstA -- D\firstAdiff -- \firstAtag}{\firstA}
\displayproblem{firstB -- D\firstBdiff -- \firstBtag}{\firstB}
\displayproblem{firstC -- D\firstCdiff -- \firstCtag}{\firstC}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\large \bf Problem bank for randomized retakes}
\vs
\hrule
\vs
\setcounter{probcounter}{0}
\displayproblem{AAA -- D\AAAdiff -- \AAAtag}{\AAA}
\displayproblem{BBB -- D\BBBdiff -- \BBBtag}{\BBB}
\displayproblem{CCC -- D\CCCdiff -- \CCCtag}{\CCC}
\displayproblem{DDD -- D\DDDdiff -- \DDDtag}{\DDD}
\displayproblem{EEE -- D\EEEdiff -- \EEEtag}{\EEE}
\displayproblem{FFF -- D\FFFdiff -- \FFFtag}{\FFF}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\large \bf Last-time quiz (final exam)}
\vs
\hrule
\vs
\setcounter{probcounter}{0}
\displayproblem{lastA -- D\lastAdiff --\lastAtag}{\lastA}
\displayproblem{lastB -- D\lastBdiff --\lastBtag}{\lastB}
\displayproblem{lastC -- D\lastCdiff --\lastCtag}{\lastC}
\end{document}