\documentclass[
	solutions,
	hidewarning,
	singlenumbering,
	nopagenumber
]{../../../lib/tex/ormc_handout}
\usepackage{../../../lib/tex/macros}


\title{Warm-Up: Turing Machine}
\uptitler{\smallurl{}}
\subtitle{Prepared by Mark on \today.}

\begin{document}

	\maketitle

	Consider a turing machine that understands the following instructions:

	\begin{itemize}[itemsep=2mm]
		\item \texttt{>}: Move the tape right
		\item \texttt{<}: Move the tape left
		\item \texttt{+}: Increment the value in the current cell by 1. \par
			If the resulting value exceeds 255, wrap to 0.
		\item \texttt{-}: Decrement the value in the current cell by 1. \par
			If the resulting value is smaller than 0, wrap to 255.
		\item \texttt{[}: If the the value of the current cell is 0, jump to the matching \texttt{]}. \par
			Otherwise, jump to the next instruction.
		\item \texttt{]}: If the value of the current cell is 0, jump to the next instruction. \par
			Otherwise, jump back to the matching \texttt{[}.
	\end{itemize}


	For example, the program \texttt{+>++>+++>++++>-} will set the first five cells to $[1, 2, 3, 4, 255]$. \par
	All other cells will be zero, since they were not modified.

	\problem{}
	What does the snippet \texttt{[-]} do? \par
	Is this different from \texttt{[+]}?

	\vfill


	\problem{}
	What does \texttt{[->+<]} do?

	\begin{solution}
		Move the value of this cell into the next cell
	\end{solution}

	\vfill

	\problem{}
	Write a program that adds the value of the current cell to the next cell. \par
	You do not need to preserve the value of the current cell.

	\vfill
	\pagebreak

	\problem{}
	What does \texttt{[>]} do?

	\begin{solution}
		Finds the first zero cell to the right
	\end{solution}

	\vfill

	\problem{}
	Write a program that copies the value of the current cell into the next cell,
	preserving its initial value. \par
	\hint{You may use as many "scratch" cells as you want.}

	\vfill


	\problem{}
	Write a program that computes the product of the current cell and the next cell.


	\vfill

	\problem{Bonus}
	Write a program that computes the square of the current cell. \par
	(If your program starts at a cell with value \texttt{7}, it should end at a cell with value \texttt{49}.)

	\vfill

	\problem{Bonus}
	What does \texttt{+[>[<-]<[->+<]>]>} do?

	\begin{solution}
		Finds the first non-zero cell to the right
	\end{solution}

\end{document}