\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{hyperref}
\usepackage[margin=1in]{geometry}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}

% tikz package and associated configuration for drawing automata
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows}
\tikzset{
->, % makes the edges directed
>=stealth', % makes the arrow heads bold
node distance=3cm, % specifies the minimum distance between two nodes. Change if necessary.
every state/.style={thick, fill=gray!10}, % sets the properties for each ’state’ node
initial text=$ $, % sets the text that appears on the start arrow
}

\title{CSCI 301 - Assignment 6, Fall 2024}
\author{Your name here}
\date{}

\newcommand{\answer}{%
  \par\noindent%
  \textbf{Answer\\}%
}

\newcommand{\inlineanswer}{%
  \hspace{1em} \textbf{Answer:} %
}

\begin{document}

\maketitle

\noindent
Modify the .tex source file for this document, adding your answers below each question.\\
This is an individual assignment. See the syllabus for the collaboration policy. \\

\hrule

Any finite automata you draw should be drawn in \LaTeX{} using Tikz. This
document contains three example FAs drawn using this library; the first of
these, below, has explanatory comments to help you understand the syntax. You
can also find a detailed tutorial on drawing FAs with Tikz here:
\url{https://www3.nd.edu/~kogge/courses/cse30151-fa17/Public/other/tikz_tutorial.pdf}.
\noindent Here is an example DFA drawn with Tikz to get you started.
Explanatory comments are included in the source file. Please delete this
paragraph and the machine below in your solutions.

\begin{tikzpicture}
% each of the following lines defines a state. For state q1:
% - initial means it's the start state; 
% - q1 is the name we give so we can refer to it elsewhere in the code;
% - $q_1$ is the label drawn on the state
\node[state, initial] (q1) {$q_1$};

% Here's state q2:
% - right of=s0 means it should be drawn to the right of state s0
% - accepting means it's an accept state; an ingoing arrow is drawn for us
\node[state, right of=q1, accepting] (q2) {$q_2$};

% Here's state q3:
% - above right means it should be drawn above and to the right of s1
\node[state, above right of=q2] (q3) {$q_3$};

% Each of the following lines defines an edge (state transition), with roughly
% the following syntax:
%   (<from_state>) edge[<options>] node{<edge label>} (<to_state>)
% where the edge options can include:
%  - a label position: above, below, left, right 
%  - a "bend" direction: left or right; if none specified, arrows are straight
%  - "loop" with a direction specifier if it's a self-loop edge
\draw (q1) edge[bend left, above] node{b} (q2) % the edge from q1 to w2
      (q1) edge[loop above] node{a} (q1) % the self-loop edge from q1 to itself
      (q2) edge[bend left, below] node{a} (q1) % the edge from q2 to q1
      (q2) edge[above] node{b} (q3) % the edge from q2 to q3
      (q3) edge[loop right] node{a, b} (q3) % the self-loop from q3 to itself
;
\end{tikzpicture}
\\ \hrule

\begin{enumerate}

    \item (5 points) Using the definition of a regular language, prove that the language $$L = \{w : w \text{ as a binary number is divisible by 4}\}$$ is regular. 




    \item (5 points) Draw a DFA that accepts the set of all strings over $\Sigma = \{0, 1\}$ that contain exactly one doubled digit in them. In other words, either 00 or 11 occurs in the string, but not both, and it only occurs once. For example, 110, 010100, 00, 1010110 would be accepted, while 0000, 101, 110100, and 11101 would be rejected. 


    \item (10 points) In this problem, you will convert the following NFA to a DFA.

\begin{tikzpicture}
\node[state, initial] (s0) {0};
\node[state, above right of=s0] (s1) {1};
\node[state, below right of=s0] (s2) {2};
\node[state, above right of=s2, accepting](s3) {3};
\draw (s0) edge[loop above] node{a} (s0)
      (s0) edge[above] node{$\epsilon$} (s1)
      (s0) edge[below] node{$a$} (s2)
      (s1) edge[loop above] node{b} (s1)
      (s1) edge[left] node{b} (s2)
      (s2) edge[bend left, above] node{a} (s3)
      (s3) edge[bend left, below] node{$\epsilon$} (s2)
;
\end{tikzpicture}

\begin{enumerate}
\item (2 points) Give the $\epsilon$-closure of each state:\\
    \begin{tabular}{r|l}
        State & $\epsilon$-closure \\\hline
        $C_\epsilon(0)$ & (your answer for state 0 goes here) \\
        $C_\epsilon(1)$ &  \\
        $C_\epsilon(2)$ &  \\
        $C_\epsilon(3)$ &  \\
    \end{tabular}
\item (3 points) Give the transition table for the DFA. Your table
    only needs to include reachable states. The first state is done
    for you; add an additional row for every reachable state.\\

    \begin{tabular}{r|cc}
        State       & $a$           & $b$           \\\hline
        $\{0,1\}$   & $\{0, 1, 2\}$ & $\{1, 2\}$    \\
    \end{tabular}

\item (5 points) Draw the resulting DFA, using states named with just the digits (for example, state $\{0, 1\}$ would be renamed $01$.
    Here's a sample tikz DFA to get you started; replace this with your machine.

\begin{tikzpicture}
\node[state, initial] (s01) {01};
\node[state, right of=s0, accepting] (s12) {12};
\draw (s01) edge[loop above] node{$b$} (s01)
      (s01) edge[bend left, above] node{$a$} (s12)
      (s12) edge[bend left, below] node{$b$} (s01)
      (s12) edge[loop above] node{$a$} (s12)
;
\end{tikzpicture}
        \end{enumerate}



\end{enumerate}

\end{document}

