\documentclass[
	solutions,
	nowarning
]{../resources/ormc_handout}


\def\stars#1{
	\count255=1
	\ifnum #1 > 0
		\loop
			{\color{cyan!50!gray} \bigstar}%
		\ifnum\count255 < #1
		\advance\count255 by 1
		\repeat
	\else%
		{\color{cyan!50!gray} \bigstar}%
	\fi%
	%
	\ifnum \count255 < 5
		\loop
			{\color{gray} \bigstar}%
		\ifnum\count255 < 4
		\advance\count255 by 1
		\repeat
	\fi
}


\NewDocumentCommand{\p}{ m m }{

	\begin{minipage}{\textwidth}
		\textbf{#1 #2:} \par

		\ifdifficulty{#1}{#2}{{\color{gray}Difficulty:} \stars{\getdifficulty{#1}{#2}}}

		\vspace{2mm}

		\getproblem{#1}{#2}

		\ifsolution{#1}{#2}{}[
			\ifanswer{#1}{#2}{%
				\vspace{2mm}%
				{\color{red}\textbf{Solution:}} \getanswer{#1}{#2}
			}
		]
	\end{minipage}

	\ifsolution{#1}{#2}{
		\begin{solution}
			\getsolution{#1}{#2}
		\end{solution}
	}

	\penalty-500

	\vspace{15mm}
	\vfill
}

\newcommand{\postproblem}[2]{
	\ifcsname#1:all\endcsname
		\expandafter\edef\csname#1:all\endcsname{\csname#1:all\endcsname \p{#1}{#2}}
	\else
		\expandafter\gdef\csname#1:all\endcsname{\p{#1}{#2}}
	\fi
}

\usepackage{problemlib}

\input{problems/numbertheory}
\input{problems/algebra}
\input{problems/combinatorics}
\input{problems/pidgeonhole}
\input{problems/misc}
\input{problems/geometry}

%\makeatletter
%\newcommand{\shoppinglist}[1]{Shopping list: #1\checknextarg}
%\newcommand{\checknextarg}{\@ifnextchar\bgroup{\gobblenextarg}{ and that's all!}}
%\newcommand{\gobblenextarg}[1]{ and also #1\@ifnextchar\bgroup%{\gobblenextarg}{ and that's all!}}
%\makeatother

\newcommand{\q}[1]{
	\section{#1}
	\csname#1:all\endcsname

	\pagebreak
}


\begin{document}
	\maketitle
		{Mark's Problem Library}
		{
			This document lists all problems in this library. \\
			Use it to find problems or debug the source.
		}


	\q{Algebra}
	\q{Combinatorics}
	\q{NumberTheory}
	\q{Pidgeonhole}
	\q{Geometry}
	\q{Misc}
\end{document}