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



% We put nodes in a separate layer, so we can
% slightly overlap with paths for a perfect fit
\pgfdeclarelayer{nodes}
\pgfsetlayers{main,nodes}

% Layer settings
\tikzset{
	% Layer hack, lets us write
	% later = * in scopes.
	layer/.style = {
		execute at begin scope={\pgfonlayer{#1}},
		execute at end scope={\endpgfonlayer}
	}
}


\title{The Electrician's Warm-Up}
\uptitler{\smallurl{}}
\subtitle{Prepared by Mark on \today}


\begin{document}

	\maketitle


	Ivan the electician is working in an apartment. He has a box of switches, which come in three types:
	\begin{center}
		\begin{minipage}[t]{0.3\textwidth}
			\begin{center}
			Plain switch
			\end{center}
			\begin{center}
			\begin{tikzpicture}
				% A state
				\node at (0.375, -1.25) {A};
				\draw[line width=1mm] (0, 0) -- (0.75, 0);

				\draw[fill=white] (0, 0) circle (1mm);
				\draw[fill=white] (0.75, 0) circle (1mm);

				% B state
				\node at (2.375, -1.25) {B};
				\draw[line width=1mm,cap=round] (2, 0) -- (2.6, 0.4);

				\draw[fill=white] (2, 0) circle (1mm);
				\draw[fill=white] (2.75, 0) circle (1mm);
			\end{tikzpicture}
			\end{center}
		\end{minipage}
		\begin{minipage}[t]{0.3\textwidth}
			\begin{center}
			Three-way switch
			\end{center}
			\begin{center}
			\begin{tikzpicture}
				% A state
				\node at (0.375, -1) {A};
				\draw[line width=1mm] (0, 0) -- (0.75, 0.5);

				\draw[fill=white] (0, 0) circle (1mm);
				\draw[fill=white] (0.75, 0.5) circle (1mm);
				\draw[fill=white] (0.75, -0.5) circle (1mm);

				% B state
				\node at (2.375, -1) {B};
				\draw[line width=1mm] (2, 0) -- (2.75, -0.5);

				\draw[fill=white] (2, 0) circle (1mm);
				\draw[fill=white] (2.75, 0.5) circle (1mm);
				\draw[fill=white] (2.75, -0.5) circle (1mm);
			\end{tikzpicture}
			\end{center}
		\end{minipage}
		\hfill
		\begin{minipage}[t]{0.3\textwidth}
			\begin{center}
				Four-way switch
			\end{center}
			\begin{center}
			\begin{tikzpicture}
				% A state
				\node at (0.375, -0.5) {A};
				\draw[line width=1mm] (0, 0) -- (0.75, 1);
				\draw[line width=1mm] (0, 1) -- (0.75, 0);

				\draw[fill=white] (0, 0) circle (1mm);
				\draw[fill=white] (0.75, 0) circle (1mm);
				\draw[fill=white] (0, 1) circle (1mm);
				\draw[fill=white] (0.75, 1) circle (1mm);

				% B state
				\node at (2.375, -0.5) {B};
				\draw[line width=1mm] (2, 0) -- (2.75, 0);
				\draw[line width=1mm] (2, 1) -- (2.75, 1);

				\draw[fill=white] (2, 0) circle (1mm);
				\draw[fill=white] (2.75, 0) circle (1mm);
				\draw[fill=white] (2, 1) circle (1mm);
				\draw[fill=white] (2.75, 1) circle (1mm);
			\end{tikzpicture}
			\end{center}
		\end{minipage}
	\end{center}

	A switch is always in the \say{A} or \say{B} state. Its state changes when you toggle the switch on the wall. Each circle represents a terminal on the switch, and lines represent electrical connections. \par
	The two crossing wires in the A state of the four-way switch are \textbf{not} connected.

	\example{}
	First, Ivan wires a simple light in the kitchen: one switch, one lamp. The result is the following circuit:

	\begin{center}
	\begin{tikzpicture}

		\begin{scope}[layer = nodes]

			\draw[fill=white] (-1.5, 0) circle (1mm);

			\node (h) at (-2, 0) {\texttt{Hot}};

			\draw[fill=white] (0, 0) circle (1mm);
			\draw[fill=white] (0.75, 0) circle (1mm);

			\node[
				circle,
				draw = black,
				fill = white,
				label = below:\texttt{Lamp}
			] (l) at (2,0) {$\circledast$};

			\draw[fill=white] (3.5, 0) circle (1mm);

			\node (n) at (4.5, 0) {\texttt{Neutral}};

		\end{scope}

		\draw[line width=1mm,cap=round] (-1.5, 0) -- (0, 0);
		\draw[line width=1mm,cap=round] (0, 0) -- (0.6, 0.4);
		\draw[line width=1mm,cap=round] (0.75, 0) -- (l);
		\draw[line width=1mm,cap=round] (l) -- (3.5,0);
	\end{tikzpicture}
	\end{center}

	\problem{}
	Ivan now needs to wire a hallway. It has two switches, one at each end. \par
	Toggling either switch should toggle the single lamp in the middle. \par
	Which switches should Ivan use, and how should he connect their terminals? \par
	\hint{There are two solutions. One is clever, the other is deadly.}

	\vfill


	\problem{}
	Next, Ivan goes to the bedroom. There is one switch by the door and one on each side of the bed. How can he make these three switches control one lamp?

	\vfill

	\problem{Bonus}
	Is it possible to do the same with four or more switches? If so, how?
\end{document}