\documentclass[11pt]{article}
\usepackage{amsmath, amsfonts, amsthm, amssymb}  % Some math symbols
\usepackage{enumerate}
\usepackage{fullpage}

\usepackage[x11names, rgb]{xcolor}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{snakes,arrows,shapes}

\usepackage{listings}
\usepackage{minted}

\setlength{\parindent}{0pt}
\setlength{\parskip}{5pt plus 1pt}
\pagestyle{empty}

\def\indented#1{\list{}{}\item[]}
\let\indented=\endlist

\newcounter{questionCounter}
\newenvironment{question}[2][\arabic{questionCounter}]{%
    \addtocounter{questionCounter}{1}%
    \setcounter{partCounter}{0}%
    \vspace{.25in} \hrule \vspace{0.5em}%
        \noindent{\bf #2}%
    \vspace{0.8em} \hrule \vspace{.10in}%
}{}

\newcounter{partCounter}[questionCounter]
\renewenvironment{part}[1][\alph{partCounter}]{%
    \addtocounter{partCounter}{1}%
    \vspace{.10in}%
    \begin{indented}%
       {\bf (#1)} %
}{\end{indented}}

%%%%%%%%%%%%%%%%% Identifying Information %%%%%%%%%%%%%%%%%
%% This is here, so that you can make your homework look %%
%% pretty when you compile it.                           %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\myname}{Michael Lee}
\newcommand{\myemail}{mlee42@cs.washington.edu}
\newcommand{\myhwname}{CSE 311: Sample Homework}
\newcommand{\mysection}{Section AB}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%% Custom Commands %%%%%%%%%%%%%%%%%%%%%
%% Adam's template doesn't contain this section, but we  %%
%% define our own custom commands for convenience below. %%
%%                                                       %%
%% For example, I personally can never remember the      %%
%% '\vee' and '\wedge' commands; I prefer using '\conj'  %%
%% and '\disj' for "conjunction" and "disjunction"       %%
%% instead. Similarly, I think constantly typing out     %%
%% '\frac{...}{...}' is a mouthful; it would be nice if  %%
%% I could use something shorter like \f{...}{...}.      %%
%%                                                       %%
%% Making custom commands is a great way to make writing %%
%% LaTeX a little move convenient!                       %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\conj}{\wedge}
\newcommand{\disj}{\vee}
\newcommand{\f}[2]{\frac{#1}{#2}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%% Custom Packages %%%%%%%%%%%%%%%%%%%%%
%% Here are some additional packages not loaded by       %%
%% Adam's template. Note that to use circuitikz, we      %%
%% normally need to load the 'tikz' pakage first, but    %%
%% Adam's template already does that up above.           %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{circuitikz}
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{center}
    {\Large \myhwname} \\
    \myemail \\
    \mysection \\
    \today
\end{center}

\begin{question}{1. Celebration?}
    Let $x$ be the number of slices of the cake.  The problem tells us that 
    we have $x = \frac{x}{4} + \frac{x}{2} + \frac{x}{6} + 3$.  Simplifying, 
    we get
    \begin{align*}
          x &= \frac{x}{4} + \frac{x}{2} + \frac{x}{6} + 3 \\
        12x &= 3x + 6x + 2x + 36 \\
          x &= 36
    \end{align*}

    Therefore, we know the cake originally had 36 slices.
\end{question}

\newpage

\begin{question}{2. Propositional Logic}
    \begin{part}
        We define our variables as:

        \begin{itemize}
            \item $p$: I know \LaTeX{}
            \item $q$: I can write fancy papers
            \item $r$: I can write homework assignments
        \end{itemize}

        Then, the sentence ``If I know \LaTeX{}, then I can write fancy papers,
        homework assignments, or both." can be expressed as:
        $$
        p \to (q \disj r)
        $$
    \end{part}
    
    \begin{part}
        The truth table:
        
        \begin{center}
            \begin{tabular}{cccc|c}
                $p$ & $q$ & $r$ & $(q \disj r)$ & $p \to (q \disj r)$ \\
                \hline
                T & T & T & T & T \\
                T & T & F & T & T \\
                T & F & T & T & T \\
                T & F & F & F & F \\
                F & T & T & T & T \\
                F & T & F & T & T \\
                F & F & T & T & T \\
                F & F & F & F & T \\
            \end{tabular}
        \end{center}
    \end{part}
    
    \begin{part}
        % The 'minipage' environment lets us insert 'miniature pages',
        % which we can use to make 'columns'. (minipage isn't the only way
        % we can have columns though).
        %
        % I'm going to insert two minipages, both that are 48% of the
        % width of the page. Why 48%? Exactly 50% tends to be a little 
        % too tight.
        %
        % The optional [t] directive makes the two minipages align towards
        % the top if they happen to have different heights. Try removing both
        % [t] directives and see what happens!
        \begin{minipage}[t]{0.48\textwidth}
            The circuit (using an embedded image): 
            \begin{center}
                \includegraphics[width=\textwidth]{logic-diagram}
            \end{center}
        \end{minipage}
        \hfill  % '\hfill' fills in whatever horizontal space is left.
        \begin{minipage}[t]{0.48\textwidth}
            The circuit (using the Circuitikz package):
            \begin{center}
                % I want to use 'thick' lines
                \begin{circuitikz}[thick] \draw
                    % Text for three inputs.
                    %
                    % Note: 'pIn', 'qIn', and 'rIn' are the names I
                    % came up with to give to these three nodes. I could
                    % have just as easily used other names.
                    %
                    % The way these commands go is:
                    %
                    % (X/Y COORDS) node[MODIFIERS] (NAME) {TEXT}
                    %
                    % Note that the modifiers and the text are optional.
                    % 
                    % To connect together two named nodes, you do:
                    %
                    % (NODE1) -- (NODE2)
                    (0, 2) node (pIn) {$p$}
                    (0, 0.8) node (qIn) {$q$}
                    (0, 0.2) node (rIn) {$r$}

                    % NOT gate, and connections to NOT gate. As before,
                    % 'port1' is a name I came up with.
                    (2, 2) node[not port] (port1) {}
                    (pIn) -- (port1.in)

                    % OR gate taking in q and r.
                    (2.5, 0.5) node[or port] (port2) {}
                    (qIn) -- (port2.in 1)
                    (rIn) -- (port2.in 2)

                    % Final OR gate
                    (5, 1.25) node[or port] (port3) {}
                    (port1.out) -- (port3.in 1)
                    (port2.out) -- (port3.in 2)

                    % Text for output
                    (port3.out) node[anchor=west] {output}
                ;
                \end{circuitikz}
            \end{center}
            
        \end{minipage}
    \end{part}

    \newpage
    
    \begin{part}
        The code is as follows:
        
        % Note: the minted package requires you to have Python and the
        % Python 'pygments' library installed. If you don't have either
        % installed, look into using the 'lstlisting' package for highlighting
        % code instead.
        %
        % Alternatively, use ShareLaTeX, which has everything pre-installed.
        \begin{minted}{java}
            public boolean foo(boolean p, boolean q, boolean r) {
                return !p || (q || r);
            }
        \end{minted}
    \end{part}

    \begin{part}
        We prove that $p \to (q \disj r)$ is equivalent to 
        $\neg q \to (q \to r)$ below:
        % The 'align*' package can also be used to add 'annotations' aligned
        % some distance to the right. We align those 'annotations' using the
        % '&&' mark.
        %
        % We're still typesetting math, so we need to make sure our text is
        % formatted correctly (instead of in italics as math variables) by
        % using the '\text{...}' command.
        \begin{align*}
            p \to (q \disj r) &\equiv \neg p \disj (q \disj r) && \text{Law of Implication} \\
                &\equiv (\neg p \disj q) \disj r && \text{Associativity} \\
                &\equiv (q \disj \neg p) \disj r && \text{Commutivity} \\
                &\equiv q \disj (\neg p \disj r) && \text{Associativity} \\
                &\equiv \neg \neg q \disj (\neg p \disj r) && \text{Double Negation} \\
                &\equiv \neg q \to (p \to r) && \text{Law of Implication}
        \end{align*}
    \end{part}
\end{question}

\newpage

\begin{question}{3. Simplification}

\begin{align*}
    6(3p - 2) - (5p + 1)(2p + 2)
        &= 6(3p - 2) - 10p^2 + 12p + 2
            && \text{Multiply right-most polynomials} \\
        &= 18p - 12 - 10p^2 + 12p + 2
            && \text{Multiply in the 6} \\
        &= -10p^2 + 30p - 10
            && \text{Combine terms} \\
\end{align*}

\end{question}

\newpage

\begin{question}{3. Sneak Peek}
    Suppose $n$ is a positive integer. We must figure out if $n(n+1)(n+2)$ is 
    evenly divisible by 6.  
    
    We know that $n$, $n+1$, and $n+2$ are three consecutive numbers. We also
    know that if we look at any two consecutive numbers, one of them must be
    divisible by 2. Likewise, if we look at any three consecutive numbers,
    one of them must be divisible by 3.

    Therefore, since $n$, $n + 1$, and $n + 2$ are consecutive numbers, and we
    know at least one of them is divisible by 2 and another by 3, we can
    conclude that the product $n(n + 1)(n + 2)$ must contain the factors $2$
    and $3$. 

    So, if the product contains those two factors, we also know that it must 
    be evenly divisible by 6.
\end{question}

\newpage

\begin{question}{4. Yummy}
    First, number the mice from $0$ to $4$ and the batches from $0$ to $29$. 
    Note that it is possible to write the numbers from 1 to 30 in binary 
    using at most $5$ bits since $2^{5} = 32 \geq 30$. We feed mouse $m$ a 
    piece of cupcake from batch $b$ if and only if the binary representation 
    of $b$ has a $1$ for the bit corresponding to $2^m$.

    We then wait $23$ hours and see which mice have died. To figure out which
    tray is tainted, we add the powers of two corresponding to each dead
    mouse together.
    The cupcake batch with the matching number is the poisoned one. 

    For clarity, we show an example with fewer mice and cupcakes in the table
    below.

    \begin{center}
    \begin{tabular}{c|c|c|c|}
                       &\textbf{Mouse 0}&\textbf{Mouse 1}&\textbf{Mouse 2}\\
    \hline
    \textbf{Batch 0}&        X       &        X       &       X        \\
    \hline
    \textbf{Batch 1}&        X       &        X       &               \\
    \hline
    \textbf{Batch 2}&        X       &                &       X         \\
    \hline
    \textbf{Batch 3}&        X       &                &                \\
    \hline
    \textbf{Batch 4}&                &        X       &       X        \\
    \hline
    \textbf{Batch 5}&                &        X       &                \\
    \hline
    \textbf{Batch 6}&                &                &       X        \\
    \hline
    \textbf{Batch 7}&                &                &                \\
    \end{tabular}
    \end{center}

    A cell in the above table has an X in it precisely when the mouse in the
    column will eat from the batch in the row.

    Notice that when any ingle batch is poisoned, a unique combination of 
    mice will die. This means using just 3 mice, we can test up to 8
    batches simultaneously.
\end{question}
\end{document}
