Merged changes
This commit is contained in:
commit
0b2c39ad63
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,10 @@
|
||||
# Output files
|
||||
main.pdf
|
||||
|
||||
# CI files
|
||||
/_build
|
||||
/_output
|
||||
|
||||
# TeX build files
|
||||
*.synctex.gz*
|
||||
*.latexmk
|
||||
|
17
.vscode/settings.json
vendored
17
.vscode/settings.json
vendored
@ -1,18 +1,3 @@
|
||||
{
|
||||
"latex-workshop.latex.recipe.default": "latexmk (lualatex)",
|
||||
"cSpell.words": [
|
||||
"Eulerian",
|
||||
"Gleizer",
|
||||
"nosolutions",
|
||||
"Oleg",
|
||||
"ORMC",
|
||||
"Pidgeonhole",
|
||||
"Radko",
|
||||
"Combinators",
|
||||
"coprime",
|
||||
"cryptosystem",
|
||||
"Fulkerson",
|
||||
"multivariable",
|
||||
"pathgroup"
|
||||
]
|
||||
"latex-workshop.latex.recipe.default": "latexmk (lualatex)"
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
% https://git.betalupi.com/Mark/latex
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[
|
||||
solutions,
|
||||
singlenumbering
|
||||
]{ormc_handout}
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amssymb}
|
||||
|
26
Advanced/Error-Correcting Codes/main.tex
Executable file
26
Advanced/Error-Correcting Codes/main.tex
Executable file
@ -0,0 +1,26 @@
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
\documentclass[
|
||||
solutions
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\usepackage{tikz}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
<Advanced 2>
|
||||
<Fall 2022>
|
||||
{Error-Correcting Codes}
|
||||
{
|
||||
Based on a handout by Yingkun Li \\
|
||||
Revised by Mark on \today
|
||||
}
|
||||
|
||||
|
||||
\input{parts/00 detection}
|
||||
\input{parts/01 correction}
|
||||
\input{parts/02 distance}
|
||||
\input{parts/03 bonus}
|
||||
|
||||
\end{document}
|
164
Advanced/Error-Correcting Codes/parts/00 detection.tex
Executable file
164
Advanced/Error-Correcting Codes/parts/00 detection.tex
Executable file
@ -0,0 +1,164 @@
|
||||
\section{Error Detection}
|
||||
|
||||
An ISBN\footnote{International Standard Book Number} is a unique numeric book identifier. It comes in two forms: ISBN-10 and ISBN-13. Naturally, ISBN-10s have ten digits, and ISBN-13s have thirteen. The final digit in both versions is a \textit{check digit}.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
Say we have a sequence of nine digits, forming a partial ISBN-10: $n_1 n_2 ... n_9$. \\
|
||||
The final digit, $n_{10}$, is calculated as follows:
|
||||
|
||||
$$
|
||||
\Biggr( \sum_{i = 1}^{9} i \times n_i \Biggl) \text{ mod } 11
|
||||
$$
|
||||
|
||||
If $n_{10}$ is equal to 10, it is written as \texttt{X}.
|
||||
|
||||
|
||||
\problem{}
|
||||
Which of the following could be valid ISBNs?
|
||||
|
||||
\begin{itemize}
|
||||
\item \texttt{0-134-54896-2}
|
||||
\item \texttt{0-307-29206-3}
|
||||
\item \texttt{0-316-00395-6}
|
||||
\end{itemize}
|
||||
|
||||
\begin{solution}
|
||||
Only the first has an inconsistent check digit.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
Show that the following sum is divisible by 11 iff $n_1n_2...n_{10}$ is a valid ISBN-10.
|
||||
$$
|
||||
\sum_{i = 1}^{10} (11 - i)n_i
|
||||
$$
|
||||
|
||||
\begin{solution}
|
||||
Proof that valid $\implies$ divisible, working in mod 11:
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
$10n_1 + 9n_2 + ... + 2n_9 + n_{10} \equiv$ \\
|
||||
$(-n_1) + (-2n_2) + ... + (-9n_9) + n_{10} =$ \\
|
||||
$-n_{10} + n_{10} \equiv 0$
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Having done this, the rest is easy. Work in reverse, or note that each step above is an iff.
|
||||
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Take a valid ISBN-10 and change one digit. Is it possible that you get another valid ISBN-10? \\
|
||||
Provide an example or a proof.
|
||||
|
||||
\begin{solution}
|
||||
Let $S$ be the sum $10n_1 + 9n_2 + ... + 2n_9 + n_{10}$, before any digits are changed.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
If you change one digit of the ISBN, $S$ changes by $km$, where $k \in \{1,2,...,10\}$ and $|m| \leq 10$. \\
|
||||
$k$ and $m$ cannot be divisible by 11, thus $km$ cannot be divisible by 11.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
We know that $S \equiv 0 \text{ (mod 11)}$. \\
|
||||
After the change, the checksum is $S + km \equiv km \not\equiv 0 \text{ (mod 11)}$.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Take a valid ISBN-10 and swap two adjacent digits. When will the result be a valid ISBN-10? \\
|
||||
This is called a \textit{transposition error}.
|
||||
|
||||
|
||||
\begin{solution}
|
||||
Let $n_1n_2...n_{10}$ be a valid ISBN-10. \\
|
||||
When we swap $n_i$ and $n_{i+1}$, we subtract $n_i$ and add $n_{i+1}$ to the checksum.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
If the new ISBN is to be valid, we must have that $n_{i+1} - n_i \equiv 0 \text{ (mod 11)}$. \\
|
||||
This is impossible unless $n_i = n_{i+1}$. Figure out why yourself.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
ISBN-13 error checking is slightly different. Given a partial ISBN-13 $n_1 n_2 n_3 ... n_{12}$, the final digit is given by
|
||||
|
||||
$$
|
||||
n_{13} = \Biggr[ \sum_{i=1}^{12} n_i \times (2 + (-1)^i) \Biggl] \text{ mod } 10
|
||||
$$
|
||||
|
||||
What is the last digit of the following ISBN-13? \\
|
||||
\texttt{978-0-380-97726-?}
|
||||
|
||||
\begin{solution}
|
||||
The final digit is 0.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Take a valid ISBN-13 and change one digit. Is it possible that you get another valid ISBN-13? \\
|
||||
Provide an example or a proof.
|
||||
|
||||
\begin{solution}
|
||||
Let $n_1n_2...n_{13}$ be a valid ISBN-13. Choose some $n_i$ and change it to $m_i$. \\
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
Since $n_i$, $m_i$ $\in \{0, 1, 2, ..., 9\}$, $-9 \leq n_i - m_i \leq 9$. \\
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Case 0: $i$ is 13 \\
|
||||
This is trivial.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Case 1: $i$ is odd \\
|
||||
For the new ISBN to be valid, we need $n_i - m_i \equiv 0 \text{ (mod 10)}$. \\
|
||||
This cannot happen if $n_i \neq m_i$.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Case 2: $i$ is even \\
|
||||
For the new ISBN to be valid, we need $3(n_i - m_i) \equiv 0 \text{ (mod 10)}$ \\
|
||||
This cannot happen, 10 and 3 are coprime.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Take a valid ISBN-13 and swap two adjacent digits. When will the result be a valid ISBN-13? \\
|
||||
\hint{The answer here is more interesting than it was last time.}
|
||||
|
||||
\begin{solution}
|
||||
Say we swap $n_i$ and $n_{i+1}$, where $i \in \{1, 2, ..., 11\}$. \\
|
||||
The checksum changes by $2(n_{i+1} - n_i)$, and will \\
|
||||
remain the same if this value is $\equiv 0 \text{ (mod 10)}$.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
\texttt{978-0-08-2066-46-6} was a valid ISBN until I changed a single digit. \\
|
||||
Can you tell me which digit I changed?
|
||||
|
||||
\begin{solution}
|
||||
Nope, unless you look at the meaning of each digit in the spec. \\
|
||||
If you're unlucky, maybe not even then.
|
||||
\end{solution}
|
||||
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
122
Advanced/Error-Correcting Codes/parts/01 correction.tex
Normal file
122
Advanced/Error-Correcting Codes/parts/01 correction.tex
Normal file
@ -0,0 +1,122 @@
|
||||
\section{Error Correction}
|
||||
|
||||
Error detection is helpful, but we'd also like to fix errors when we find them. One example of such a system is the QR code, which remains readable even if a significant amount of it is removed. QR codes with icons inside aren't special--they're just missing their central elements. The error-correcting codes in the QR specification allow us to recover the lost data.
|
||||
\begin{figure}[h]
|
||||
\centering
|
||||
\includegraphics[width = 3cm]{qr}
|
||||
\end{figure}
|
||||
|
||||
\definition{Repeating codes}
|
||||
The simplest possible error-correcting code is a \say{repeating code}. It works just as you'd expect: \\
|
||||
Instead of sending data once, it sends multiple copies. If a few bits are damaged, they can be both detected and repaired. \\
|
||||
|
||||
For example, consider the following three-repeat code encoding the binary string $101$:
|
||||
|
||||
$$
|
||||
111~000~111
|
||||
$$
|
||||
|
||||
If we flip any one bit, we can easily find and fix the error.
|
||||
|
||||
\definition{Code Efficiency}
|
||||
The efficiency of an error-correcting code is calculated as follows:
|
||||
$$
|
||||
\frac{\text{number of data bits}}{\text{total bits sent}}
|
||||
$$
|
||||
|
||||
For example, the efficiency of the three-repeat code above is $\frac{3}{9} = \frac{1}{3} \approx 0.33$
|
||||
|
||||
\problem{}
|
||||
What is the efficiency of an $k$-repeat code?
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
How many repeated digits do you need to...
|
||||
\begin{itemize}
|
||||
\item[-] detect a transposition error?
|
||||
\item[-] correct a transposition error?
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
\definition{Hamming's Square Code}
|
||||
|
||||
A more effective coding scheme comes in the form of Hamming's square code.
|
||||
Take a four-bit message and arrange it in a $2 \times 2$ square. \\
|
||||
|
||||
Compute the pairity of each row and write it at the right. \\
|
||||
Compute the pairity of each column and write it at the bottom. \\
|
||||
Finally, compute the pairity of the entire message write it in the lower right corner.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
Reading the result row by row to get the encoded message. \\
|
||||
For example, the message 1011 generates the sequence 101110011:
|
||||
|
||||
$$
|
||||
1011
|
||||
\longrightarrow
|
||||
\begin{array}{cc|}
|
||||
1 & 0 \\
|
||||
1 & 1 \\
|
||||
\hline
|
||||
\end{array}
|
||||
\longrightarrow
|
||||
\begin{array}{cc|c}
|
||||
1 & 0 & 1 \\
|
||||
1 & 1 & 0 \\ \hline
|
||||
0 & 1 &
|
||||
\end{array}
|
||||
\longrightarrow
|
||||
\begin{array}{cc|c}
|
||||
1 & 0 & 1 \\
|
||||
1 & 1 & 0 \\ \hline
|
||||
0 & 1 & 1
|
||||
\end{array}
|
||||
\longrightarrow
|
||||
101110011
|
||||
$$
|
||||
|
||||
\problem{}
|
||||
The following message are encoded using the method above.
|
||||
Find and correct any single-digit or transposition errors.
|
||||
\begin{enumerate}
|
||||
\item \texttt{110 110 011} %101110011
|
||||
\item \texttt{100 101 011} %110101011
|
||||
\item \texttt{001 010 110} %000110110
|
||||
\end{enumerate}
|
||||
|
||||
\begin{solution}
|
||||
\begin{enumerate}
|
||||
\item \texttt{101 110 011} or \texttt{110 101 011}
|
||||
\item \texttt{110 101 011}
|
||||
\item \texttt{000 110 110}
|
||||
\end{enumerate}
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
What is the efficiency of this coding scheme?
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Can we correct a single-digit error in the encoded message? \\
|
||||
Can we correct a transposition error in the encoded message?
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Let's generalize this coding scheme to a non-square table: \\
|
||||
Given a message of length $ab$, construct a rectangle with dimensions $a \times b$ as described above.
|
||||
\begin{itemize}
|
||||
\item What is the efficiency of a $a \times b$ rectangle code?
|
||||
\item Can the $a \times b$ rectangle code detect and fix single-bit errors?
|
||||
\item Can the $a \times b$ rectangle code detect and fix two-bit errors?
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
41
Advanced/Error-Correcting Codes/parts/02 distance.tex
Normal file
41
Advanced/Error-Correcting Codes/parts/02 distance.tex
Normal file
@ -0,0 +1,41 @@
|
||||
\section{Hamming Distance}
|
||||
|
||||
\definition{}
|
||||
The \textit{Hamming distance} between two strings $x = x_1x_2...x_n$ and $y = y_1y_2...y_n$ is the number of positions at which the digits of $x$ and $y$ are different.
|
||||
|
||||
\problem{}
|
||||
Compute the Hamming distance between \texttt{1010} and \texttt{0001}.
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Read $d_H(x, y)$ as \say{the hamming distance between $x$ and $y$.} \\
|
||||
Prove the following statements:
|
||||
\begin{enumerate}
|
||||
\item $d_H(x, y) \ge 0$ with equality if and only if $x = y$,
|
||||
\item $d_H(x, y) = d_H(y, x)$,
|
||||
\item $d_H(x, z) \le d_H(x, y) + d_H(y, z)$.
|
||||
\end{enumerate}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Say we encode and send a message with the 3-repeat code. A few bits are damaged in transit. \\
|
||||
When the transmission is decoded, a different message is read.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
What is the minimum possible hamming distance between the undamaged encoded message and the damaged encoded message?
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Say we encode and send a message with Hamming's square code. A few bits are damaged in transit. \\
|
||||
When the transmission is decoded, no uncorrectable errors are detected and a different message is read.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
What is the minimum possible hamming distance between the undamaged encoded message and the damaged encoded message?
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
94
Advanced/Error-Correcting Codes/parts/03 bonus.tex
Normal file
94
Advanced/Error-Correcting Codes/parts/03 bonus.tex
Normal file
@ -0,0 +1,94 @@
|
||||
\section{Hat Puzzles: The Revenge}
|
||||
|
||||
\problem{}
|
||||
Three people are sitting in a circle. A black or a white hat will be placed on each person's head, with equal probability. Each person can see everyone's hat color except their own. \\
|
||||
|
||||
\vspace{1mm}
|
||||
|
||||
The participants are asked to simultaneously write down \say{Black}, \say{White}, or \say{Pass}. \\
|
||||
They win if at least one person guesses their hat correctly. \\
|
||||
They lose if anyone guesses incorrectly, or if everyone passes.
|
||||
|
||||
\vspace{1mm}
|
||||
|
||||
How can they maximize their chance of winning?
|
||||
|
||||
\vfill
|
||||
|
||||
|
||||
\problem{}
|
||||
Consider the same game with $2^n-1$ people. How can they achieve a win rate of $\frac{2^n-1}{2^n}$?
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
% A copy of the post these problems are based on. Contains the solution.
|
||||
% https://cornellmath.wordpress.com/2007/09/20/hat-guessing-puzzles-the-revenge
|
||||
%
|
||||
% I guess since my previous hat color guessing problem was so popular, I might as well talk about the other one I know. However, this one isn't meant to attack the foundations of mathematics. The problem is as follows:
|
||||
%
|
||||
% Three people are sitting in a circle. Black or white hats (50% chance of each) will all be placed on their heads, and they will be able to see everyone's hat color but their own. They will all simultaneously write down on a piece of paper either "Black", "White", or "Pass", trying to guess their own hat color. All the people collectively win (whatever that means) if at least someone guesses their hat correctly and no one guesses incorrectly. They lose if anyone guesses incorrectly, or everyone passes. If they can agree on a strategy beforehand, what is their best chance of winning?
|
||||
%
|
||||
% Again, there is the problem that no information can be conveyed to someone about their own hat color, so they would seem to be guessing blindly (talking and facial expressions are prohibited). However, they can still win 75% of the time. Figure it out!
|
||||
%
|
||||
% Once you solve the easy version of this puzzle, the harder version is with larger numbers of people. As a partial spoiler, stick to 2^n-1, where the best win rate is 2^n-1 out of 2^n. How is this possible? (Answer below the fold)
|
||||
%
|
||||
% The trick to the puzzle is realizing that, even though any specific person who elects not to pass has only a 50% chance of being right, the strategy can be chosen so that the wrong guesses are all concentrated into a small number of possibilities. That is, because you only need % one right guess to win and multiple wrong guesses don't make a loss worse, the strategy should attempt to make as many people wrong simultaneously if anyone is going to guess wrong.
|
||||
%
|
||||
% The three-person case makes a good example. Consider the following strategy:
|
||||
%
|
||||
% If you see two hats of the same color: Guess the opposite color.
|
||||
%
|
||||
% If you see two different hat colors: Pass.
|
||||
%
|
||||
% What happens? It's not hard to write down all the possibilities:
|
||||
%
|
||||
% 3 black hats: Everyone sees two black hats, and guesses White. Everyone is wrong.
|
||||
%
|
||||
% 2 black hats, 1 white hat: The people in black hats see both colors and Pass; the person in the white hat sees two black hats and says White. One person is correct and everyone else passed.
|
||||
%
|
||||
% 1 black hat, 2 white hats: This is identical to the previous case, with colors reversed. Its a win.
|
||||
%
|
||||
% 3 white hats: This is identical to the first case, with colors reversed. Its a loss.
|
||||
%
|
||||
% So unless all three hats were the same color, everyone won. However, the chances of all three hats being the same color is only 1 in 4, so its a win 75% of the time. Notice that the key was getting everyone to be wrong at the same time, but only having one correct guess in winning situations.
|
||||
%
|
||||
% Ok, what about more people, say, n of them? Well, we need a strategy where the wrong guesses are concentrated and the right guesses are spread out. Let's make this a little bit more mathematical, by turning white hats into 1s and black hats into 0s. Now, a possible hat scenario is a sequence of n binary digits, and every sequence is equally likely.
|
||||
%
|
||||
% Since the optimal strategy seems to be when all the wrong guesses happen simultaneously, we need to agree on some sequences that will be the wrong sequences, that is, the scenarios where everyone will guess incorrectly. How does this work? Say 0000000 is one of the agreed upon wrong sequences (this is for n=7). Then, if someone looks around and sees all zeros/black hats, they will guess white. That way, everyone will be wrong if it is all black hats; but if there is exactly one white hat, everyone wins! Since it is n times more likely for there to be exactly one white hat than no white hats, this seems to work pretty well.
|
||||
%
|
||||
% The general strategy if you have a whole bunch of wrong sequences is for everyone to look around, and:
|
||||
%
|
||||
% If it looks like you might be in a wrong sequence, guess the opposite possibility.
|
||||
%
|
||||
% If you are definitely not in a wrong sequence, pass.
|
||||
%
|
||||
% (Note that we are assuming that no two wrong sequences differ by a single digit, so that there is always an 'opposite possiblity') How well does this strategy work?
|
||||
%
|
||||
% It loses every wrong sequence.
|
||||
%
|
||||
% It wins every sequence that differs from a wrong sequences by exactly one digit.
|
||||
%
|
||||
% It loses every sequence that differs from every wrong sequence by at least two digits (since everyone passes).
|
||||
%
|
||||
% So what we want is a collection of wrong sequences that are evenly spread out amongst the possibilities, ie, we want to 'cover' as many possibilites as possible with the fewest number of wrong sequences.
|
||||
%
|
||||
% This is actually a problem that real people care about, even some who don't wear hats. This is (roughly) the problem of finding an error correcting code. Sometimes, one computer will be sending another computer information in the form of a sequence of 1s and 0s, and by some fluke % a single digit will get flipped. The goal of error correcting codes is to turn the sequence of 1s and 0s you want to send into a longer sequence, which has the property that the receiving computer can tell if a digit got flipped and repair it.
|
||||
%
|
||||
% A silly example is the Tripling Code, where if what I want to do is send you 011, I instead send you 011011011 (we always agree on what code we are using ahead of time). Now, if one digit gets flipped, you will see two of the three copies of the sequence agreeing and one differing, and you will know what I was trying to say. However, this is a wildly inefficient code, since it takes three times as long to say anything.
|
||||
%
|
||||
% What does an error-correcting code look like? Well, we agree ahead of time upon which possible sequences are the codewords (ie, the ones that are correct), and how to turn them into the messages we really wanted to send. Then, if you get something that differs from a codeword by % exactly one digit, you know how to correct it (this is assuming that the codewords are far enough apart that there is only one close one). So the goal for making an efficient code is to pick codewords spread apart evenly enough that as many possible sequences are exactly one away % from a codeword. This is exactly what we were looking for with our 'wrong sequences', even though the names were different.
|
||||
%
|
||||
% Therefore, we can invoke some fancy error-correcting codes to find the optimal hat guessing strategy. In particular, if the number of people/length of sequence is 2^n-1, there is a 'perfect code' called the Hamming code, which will give us a choice of wrong sequences such that every possibility is either 1) a wrong sequence, or 2) exactly 1 digit away from a wrong sequence. Hence, this is best possible strategy for hat guessing. I am not going into the details of the Hamming codes, since the important thing here is that they exist.
|
||||
%
|
||||
% However, this only solves the problem for a very specific number of people. What about other numbers? Theres a complication in these cases, in that its impossible to have a perfect code. That is, it is impossible to choose wrong sequences so that every possible sequence is either wrong, or one digit away from exactly one wrong sequence.
|
||||
%
|
||||
% We can ask what the nearest possibility to a perfect code is, but its not clear which way to be less than perfect is optimal:
|
||||
%
|
||||
% 1) Having some of the correct guesses overlap, that is, having some wrong sequences differ by 2 digits.
|
||||
%
|
||||
% 2) Having some sequences which are lost because everyone passes.
|
||||
%
|
||||
% 3) Most significantly, moving away from the 'wrong sequence' strategy.
|
||||
%
|
||||
% The last one, which I would guess is the correct way to proceed, is bad because the tools from computer science become useless rapidly. I really have no idea what the optimal solution looks like here.
|
BIN
Advanced/Error-Correcting Codes/qr.png
Normal file
BIN
Advanced/Error-Correcting Codes/qr.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 89 KiB |
@ -1,11 +1,9 @@
|
||||
% https://git.betalupi.com/Mark/latex
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[
|
||||
singlenumbering,
|
||||
nosolutions
|
||||
]{ormc_handout}
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amssymb}
|
||||
@ -115,7 +113,7 @@
|
||||
We know that for any $\epsilon$, $\exists p$ so that $\frac{1}{p} = \epsilon$. This is the \textit{Archemedian Property}. \\
|
||||
It is now clear that $\lim_{n\to\infty}a_n = 0$
|
||||
|
||||
\boxlinehack
|
||||
\linehack{}
|
||||
|
||||
$\lim_{n\to\infty}a_n = \pi$ means that $\forall \epsilon > 0$, $\exists N \in \mathbb{N}$ so that $|a_n - \pi| < \epsilon\ \forall n < N$. \\
|
||||
|
||||
@ -149,7 +147,7 @@
|
||||
|
||||
Therefore, if both $A$ and $B$ are limits of $[a_n]$, $A$ and $B$ must be equal.
|
||||
|
||||
\boxlinehack
|
||||
\linehack{}
|
||||
|
||||
\textsuperscript{*}Note that we can also set $\epsilon = \frac{|B-A|}{2}$, which gives $|B-A| < |B-A|$. This is also false, and the proof still works. However, the extra $\frac{\hspace{2em}}{2}$ gives a clearer explanation.
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[
|
||||
solutions
|
||||
]{ormc_handout}
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
|
||||
\input{tikxset}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
\definition{}
|
||||
A \textit{graph} consists of a set of \textit{nodes} $\{A, B, ...\}$ and a set of edges $\{ (A,B), (A,C), ...\}$ connecting them.
|
||||
A \textit{directed graph} is a graph where edges have direction. In such a graph, $(A, B)$ and $(B, A)$ are distinct edges.
|
||||
A \textit{directed graph} is a graph where edges have direction. In such a graph, edges $(A, B)$ and $(B, A)$ are distinct.
|
||||
A \textit{weighted graph} is a graph that features weights on its edges. \\
|
||||
A weighted directed graph is shown below.
|
||||
|
||||
@ -28,8 +28,7 @@ A weighted directed graph is shown below.
|
||||
\vfill
|
||||
|
||||
\definition{}
|
||||
We say a graph is \textit{bipartite} if its nodes can be split into two groups $L$ and $R$ so that no two nodes in the same group are connected by an edge. \\
|
||||
The following graph is bipartite:
|
||||
We say a graph is \textit{bipartite} if its nodes can be split into two groups $L$ and $R$, where no two nodes in the same group are connected by an edge: \\
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
@ -39,9 +38,9 @@ The following graph is bipartite:
|
||||
\node[main] (B) at (0mm, -10mm) {$B$};
|
||||
\node[main] (C) at (0mm, -20mm) {$C$};
|
||||
|
||||
\node[main] (D) at (20mm, 0mm) {$D$};
|
||||
\node[main] (E) at (20mm, -10mm) {$E$};
|
||||
\node[main] (F) at (20mm, -20mm) {$F$};
|
||||
\node[main, hatch] (D) at (20mm, 0mm) {$D$};
|
||||
\node[main, hatch] (E) at (20mm, -10mm) {$E$};
|
||||
\node[main, hatch] (F) at (20mm, -20mm) {$F$};
|
||||
\end{scope}
|
||||
|
||||
% Edges
|
||||
@ -55,30 +54,5 @@ The following graph is bipartite:
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\vfill
|
||||
|
||||
\definition{}
|
||||
We say two nodes $A$ ane $B$ are \textit{connected} if we can reach $A$ from $B$ and $B$ from $A$ by walking along (possibly directed) edges. We say a graph is connected if all its nodes are connected to each other.\\
|
||||
|
||||
The bipartite graph above and the directed graph below are not connected.
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}[node distance = 20mm]
|
||||
% Nodes
|
||||
\begin{scope}
|
||||
\node[main] (A) {$A$};
|
||||
\node[main] (B) [below right of = A] {$B$};
|
||||
\node[main] (C) [below left of = A] {$C$};
|
||||
\end{scope}
|
||||
|
||||
% Edges
|
||||
\draw[->]
|
||||
(A) edge[bend right] (B)
|
||||
(B) edge[bend right] (A)
|
||||
(B) edge (C)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
@ -1,23 +1,23 @@
|
||||
\section{Network Flow}
|
||||
|
||||
\generic{Networks}
|
||||
Say have a network: a sequence of pipes, a set of cities and highways, an electrical circuit, server infrastructure, etc.
|
||||
Say have a network: a sequence of pipes, a set of cities and highways, an electrical circuit, etc.
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
We'll represent our network with a connected directed weighted graph. If we take a city, edges will be highways and cities will be nodes. There are a few conditions for a valid network graph:
|
||||
We can draw this network as a directed weighted graph. If we take a transporation network, for example, edges will represent highways and nodes will be cities. There are a few conditions for a valid network graph:
|
||||
|
||||
\begin{itemize}
|
||||
\item The weight of each edge represents its capacity, the number of lanes in the highway.
|
||||
\item The weight of each edge represents its capacity, e.g, the number of lanes in the highway.
|
||||
\item Edge capacities are always positive integers.\hspace{-0.5ex}\footnotemark{}
|
||||
\item Node $S$ is a \textit{source}: it produces flow.
|
||||
\item Node $T$ is a \textit{sink}: it consumes flow.
|
||||
\item All other nodes \textit{conserve} flow. In other words, the sum of flow coming in must equal the sum of flow going out.
|
||||
\item All other nodes \textit{conserve} flow. The sum of flow coming in must equal the sum of flow going out.
|
||||
\end{itemize}
|
||||
|
||||
\footnotetext{An edge with capacity zero is equivalent to an edge that does not exist; An edge with negative capacity is equivalent to an edge in the opposite direction.}
|
||||
|
||||
Here is an example of a such a graph:
|
||||
Here is an example of such a graph:
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
|
||||
@ -43,7 +43,7 @@ Here is an example of a such a graph:
|
||||
\hrule{}
|
||||
|
||||
\generic{Flow}
|
||||
In our city example, cars represent \textit{flow}. Let's send one unit of cars along the topmost highway:
|
||||
In our city example, traffic represents \textit{flow}. Let's send one unit of traffic along the topmost highway:
|
||||
|
||||
\vspace{2ex}
|
||||
|
||||
@ -89,11 +89,9 @@ In our city example, cars represent \textit{flow}. Let's send one unit of cars a
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
The \textit{magnitude} of a flow\footnotemark{} is the number of \say{flow-units} that go from $S$ to $T$. \\
|
||||
The \textit{magnitude} of a flow is the number of \say{flow-units} that go from $S$ to $T$. \\
|
||||
|
||||
We are interested in the \textit{maximum flow} through this network: what is the greatest amount of flow we can push from $S$ to $T$?
|
||||
|
||||
\footnotetext{you could also think of \say{flow} as a directed weighted graph on top of our network.}
|
||||
We are interested in the \textit{maximum flow} through this network: what is the greatest amount of flow we can get from $S$ to $T$?
|
||||
|
||||
\problem{}
|
||||
What is the magnitude of the flow above?
|
||||
@ -156,7 +154,8 @@ Find a maximal flow on the graph below. \\
|
||||
\pagebreak
|
||||
|
||||
\section{Combining Flows}
|
||||
It is fairly easy to combine two flows on a graph. All we need to do is add the flows along each edge. For example, consider the following flows:
|
||||
It is fairly easy to combine two flows on a graph. All we need to do is add the flows along each edge. \\
|
||||
Consider the following flows:
|
||||
|
||||
\vspace{2ex}
|
||||
|
||||
@ -266,11 +265,7 @@ It is fairly easy to combine two flows on a graph. All we need to do is add the
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
For example, we could not add these graphs if the magnitude of flow in the right graph above was 2.
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
This is because the capacity of the top-right edge is 2, and $2 + 1 > 2$.
|
||||
For example, we could not add these graphs if the magnitude of flow in the right graph above was 2, since the capacity of the top-right edge is 2, and $2 + 1 > 2$.
|
||||
\end{minipage}
|
||||
|
||||
\vspace{2ex}
|
||||
@ -278,7 +273,7 @@ It is fairly easy to combine two flows on a graph. All we need to do is add the
|
||||
\vspace{2ex}
|
||||
|
||||
\problem{}
|
||||
Combine the following flows and ensure that the flow along all edges remains within capacity.
|
||||
Combine the flows below, ensuring that the flow along each edge remains within capacity.
|
||||
|
||||
\vspace{2ex}
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
\section{Residual Graphs}
|
||||
As our network gets bigger, finding a maximum flow by hand becomes much more difficult. It will be convenient to have an algorithm that finds a maximal flow in any network.
|
||||
It is hard to find a maximum flow for a large network by hand. \\
|
||||
We need to create an algorithm to accomplish this task.
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
The first thing we'll need to construct such an algorithm is a \textit{residual graph}.
|
||||
The first thing we'll need is the notion of a \textit{residual graph}.
|
||||
|
||||
\vspace{2ex}
|
||||
\hrule
|
||||
@ -202,11 +203,9 @@ If it isn't, find a maximal flow. \\
|
||||
\problem{}
|
||||
Show that...
|
||||
\begin{enumerate}
|
||||
\item A maximal flow exists in every network with integral\footnotemark{} edge weights.
|
||||
\item A maximal flow exists in every network with integral edge weights.
|
||||
\item Every edge in this flow carries an integral amount of flow
|
||||
\end{enumerate}
|
||||
|
||||
\footnotetext{Integral = \say{integer} as an adjective.}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
@ -108,7 +108,7 @@ There is extra space on the next page.
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
You are given a large network. How would you quickly find an upper bound for the number of iterations the Ford-Fulkerson algorithm will need to find a maximum flow?
|
||||
You are given a large network. How can you quickly find an upper bound for the number of iterations the Ford-Fulkerson algorithm will need to find a maximum flow?
|
||||
|
||||
\begin{solution}
|
||||
Each iteration adds at least one unit of flow. So, we will find a maximum flow in at most $\min(\text{flow out of } S,~\text{flow into } T)$ iterations.
|
||||
|
@ -86,8 +86,9 @@ A matching is \textit{maximal} if it has more edges than any other matching.
|
||||
|
||||
\vspace{5mm}
|
||||
|
||||
Devise an algorithm to find a maximal matching in any bipartite graph. \\
|
||||
Find an upper bound for its runtime.
|
||||
Create an algorithm that finds a maximal matching in any bipartite graph. \\
|
||||
Find an upper bound for its runtime. \\
|
||||
\hint{Can you modify an algorithm we already know?}
|
||||
|
||||
\begin{solution}
|
||||
Turn this into a maximum flow problem and use FF. \\
|
||||
@ -101,7 +102,7 @@ Find an upper bound for its runtime.
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
\problem{Circulations with Demand}
|
||||
\problem{Supply and Demand}
|
||||
|
||||
Say we have a network of cities and power stations. Stations produce power; cities consume it.
|
||||
|
||||
@ -146,7 +147,7 @@ We'll represent station capacity with a negative number, since they \textit{cons
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
We'd like to know if there exists a \textit{feasible circulation} in this network---that is, can we supply our cities with the energy they need without exceeding the capacity of power plants or transmission lines?
|
||||
We'd like to know if there exists a \textit{feasible circulation} in this network---that is, can we supply our cities with the energy they need without exceeding the capacity of our power plants and transmission lines?
|
||||
|
||||
\vspace{2ex}
|
||||
|
||||
|
@ -8,11 +8,7 @@ An \textit{independent set} is a set of vertices\footnotemark{} in which no two
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}[
|
||||
node distance = 12mm,
|
||||
hatch/.style = {
|
||||
pattern=north west lines,
|
||||
pattern color=gray
|
||||
}
|
||||
node distance = 12mm
|
||||
]
|
||||
% Nodes
|
||||
\begin{scope}[layer = nodes]
|
||||
@ -48,11 +44,7 @@ A \textit{vertex cover} is a set of vertices that includes at least one endpoint
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}[
|
||||
node distance = 12mm,
|
||||
hatch/.style = {
|
||||
pattern=north west lines,
|
||||
pattern color=gray
|
||||
}
|
||||
node distance = 12mm
|
||||
]
|
||||
% Nodes
|
||||
\begin{scope}[layer = nodes]
|
||||
|
@ -1,6 +1,6 @@
|
||||
\section{Crosses (Bonus Problem)}
|
||||
\section{Crosses}
|
||||
|
||||
You are given an $n \times n$ grid. Some of its squares are white, and some are gray. Your goal is to place $n$ crosses on white cells so that each row and each column contains exactly one cross.
|
||||
You are given an $n \times n$ grid. Some of its squares are white, some are gray. Your goal is to place $n$ crosses on white cells so that each row and each column contains exactly one cross.
|
||||
|
||||
\vspace{2ex}
|
||||
|
||||
|
@ -49,5 +49,9 @@
|
||||
% completely under nodes.
|
||||
line cap = rect,
|
||||
opacity = 0.3
|
||||
},
|
||||
hatch/.style = {
|
||||
pattern=north west lines,
|
||||
pattern color=gray
|
||||
}
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
% https://git.betalupi.com/Mark/latex
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
|
||||
\documentclass[
|
||||
solutions,
|
||||
singlenumbering
|
||||
]{ormc_handout}
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\usepackage{url}
|
||||
\usepackage{mathtools} % for \coloneqq
|
||||
|
@ -1,10 +1,8 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[
|
||||
solutions
|
||||
]{ormc_handout}
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amssymb}
|
||||
|
@ -1,11 +1,8 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.0.6
|
||||
\documentclass[
|
||||
solutions,
|
||||
simplefooter
|
||||
]{ormc_handout}
|
||||
solutions
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
|
||||
\usepackage{tkz-graph}
|
||||
|
@ -1,8 +1,6 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[solutions]{ormc_handout}
|
||||
\documentclass[solutions]{../../resources/ormc_handout}
|
||||
|
||||
\newcommand{\nck}[2] {
|
||||
\ensuremath{
|
||||
|
@ -1,10 +1,8 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[
|
||||
solutions
|
||||
]{ormc_handout}
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
|
||||
\usepackage{tkz-graph}
|
||||
|
@ -1,8 +1,8 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.0.6
|
||||
\documentclass[solutions, simplefooter]{ormc_handout}
|
||||
\documentclass[
|
||||
solutions
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
@ -1,8 +1,6 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[solutions]{ormc_handout}
|
||||
\documentclass[solutions]{../../resources/ormc_handout}
|
||||
|
||||
|
||||
% Quick P() macro.
|
||||
|
@ -1,10 +1,8 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[
|
||||
solutions
|
||||
]{ormc_handout}
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\usepackage{pdfpages}
|
||||
\usepackage{sliderule}
|
||||
|
534
Intermediate/Slide Rules/sliderule.sty
Executable file
534
Intermediate/Slide Rules/sliderule.sty
Executable file
@ -0,0 +1,534 @@
|
||||
\NeedsTeXFormat{LaTeX2e}
|
||||
\ProvidesPackage{sliderule}[2022/08/22 Slide rule tools]
|
||||
|
||||
\RequirePackage{tikz}
|
||||
\RequirePackage{ifthen}
|
||||
|
||||
|
||||
% Scale functions:
|
||||
% See https://sliderulemuseum.com/SR_Scales.htm
|
||||
%
|
||||
% l: length of the rule
|
||||
% n: the number on the rule
|
||||
%
|
||||
% A/B: (l/2) * log(n)
|
||||
% C/D: l / log(n)
|
||||
% CI: abs(l * log(10 / n) - l)
|
||||
% K: (l/3) * log(n)
|
||||
%
|
||||
% L: n * l
|
||||
% T: l * log(10 * tan(n))
|
||||
% S: l * log(10 * sin(n))
|
||||
|
||||
\def\sliderulewidth{10}
|
||||
|
||||
\def\abscalefn(#1){(\sliderulewidth/2) * log10(#1)}
|
||||
\def\cdscalefn(#1){(\sliderulewidth * log10(#1))}
|
||||
\def\ciscalefn(#1){(\sliderulewidth - \cdscalefn(#1))}
|
||||
\def\kscalefn(#1){(\sliderulewidth/3) * log10(#1)}
|
||||
\def\lscalefn(#1){(\sliderulewidth * #1)}
|
||||
\def\tscalefn(#1){(\sliderulewidth * log10(10 * tan(#1)))}
|
||||
\def\sscalefn(#1){(\sliderulewidth * log10(10 * sin(#1)))}
|
||||
|
||||
|
||||
% Arguments:
|
||||
% Label
|
||||
% x of start
|
||||
% y of start
|
||||
\newcommand{\linearscale}[3]{
|
||||
\draw[black] ({#1}, #2) -- ({#1 + \sliderulewidth}, #2);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.9);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1}, #2 + 0.7);
|
||||
\draw[black] ({#1 + \sliderulewidth}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.7);
|
||||
|
||||
\draw ({#1 - 0.1}, #2 + 0.5) node[left] {#3};
|
||||
|
||||
% Numbers and marks
|
||||
\foreach \i in {0,..., 10}{
|
||||
\draw[black]
|
||||
({#1 + (\sliderulewidth / 10) * \i}, #2) --
|
||||
({#1 + (\sliderulewidth / 10) * \i}, #2 + 0.3)
|
||||
node[above] {\i};
|
||||
}
|
||||
|
||||
% Submarks
|
||||
\foreach \n in {0, ..., 9} {
|
||||
\foreach \i in {1,..., 9} {
|
||||
\ifthenelse{\i=5}{
|
||||
\draw[black]
|
||||
({#1 + (\sliderulewidth / 10) * (\n + \i / 10)}, #2) --
|
||||
({#1 + (\sliderulewidth / 10) * (\n + \i / 10)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + (\sliderulewidth / 10) * (\n + \i / 10)}, #2) --
|
||||
({#1 + (\sliderulewidth / 10) * (\n + \i / 10)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
% Arguments:
|
||||
% Label
|
||||
% x of start
|
||||
% y of start
|
||||
\newcommand{\abscale}[3]{
|
||||
\draw[black] ({#1}, #2) -- ({#1 + \sliderulewidth}, #2);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.9);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1}, #2 + 0.7);
|
||||
\draw[black] ({#1 + \sliderulewidth}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.7);
|
||||
|
||||
|
||||
\draw ({#1 - 0.1}, #2 + 0.5) node[left] {#3};
|
||||
|
||||
% Numbers and marks 1 - 9
|
||||
\foreach \i in {1,..., 9}{
|
||||
\draw[black]
|
||||
({#1 + \abscalefn(\i)}, #2) --
|
||||
({#1 + \abscalefn(\i)}, #2 + 0.3)
|
||||
node[above] {\i};
|
||||
}
|
||||
% Numbers and marks 10 - 100
|
||||
\foreach \i in {1,..., 10}{
|
||||
\draw[black]
|
||||
({#1 + \abscalefn(10 * \i)}, #2) --
|
||||
({#1 + \abscalefn(10 * \i)}, #2 + 0.3)
|
||||
node[above] {\ifthenelse{\i=10}{1}{\i}};
|
||||
}
|
||||
|
||||
% Submarks 1 - 9
|
||||
\foreach \n in {1, ..., 9} {
|
||||
\ifthenelse{\n<5}{
|
||||
\foreach \i in {1,..., 9}
|
||||
} {
|
||||
\foreach \i in {2,4,6,8}
|
||||
}
|
||||
{
|
||||
\ifthenelse{\i=5}{
|
||||
\draw[black]
|
||||
({#1 + \abscalefn(\n + \i / 10)}, #2) --
|
||||
({#1 + \abscalefn(\n + \i / 10)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \abscalefn(\n + \i / 10)}, #2) --
|
||||
({#1 + \abscalefn(\n + \i / 10)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
% Submarks 10 - 100
|
||||
\foreach \n in {10,20,...,90} {
|
||||
\ifthenelse{\n<50}{
|
||||
\foreach \i in {1,..., 9}
|
||||
} {
|
||||
\foreach \i in {2,4,6,8}
|
||||
}
|
||||
{
|
||||
\ifthenelse{\i=5}{
|
||||
\draw[black]
|
||||
({#1 + \abscalefn(\n + \i)}, #2) --
|
||||
({#1 + \abscalefn(\n + \i)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \abscalefn(\n + \i)}, #2) --
|
||||
({#1 + \abscalefn(\n + \i)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\newcommand{\cdscale}[3]{
|
||||
\draw[black] ({#1}, #2) -- ({#1 + \sliderulewidth}, #2);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.9);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1}, #2 + 0.7);
|
||||
\draw[black] ({#1 + \sliderulewidth}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.7);
|
||||
|
||||
|
||||
\draw ({#1 - 0.1}, #2 + 0.5) node[left] {#3};
|
||||
|
||||
% Numbers and marks 1 - 10
|
||||
\foreach \i in {1,..., 10}{
|
||||
\draw[black]
|
||||
({#1 + \cdscalefn(\i)}, #2) --
|
||||
({#1 + \cdscalefn(\i)}, #2 + 0.3)
|
||||
node[above] {\ifthenelse{\i=10}{1}{\i}};
|
||||
}
|
||||
|
||||
% Submarks 1 - 9
|
||||
\foreach \n in {1, ..., 9} {
|
||||
\ifthenelse{\n<3}{
|
||||
\foreach \i in {5,10,...,95}
|
||||
} {
|
||||
\foreach \i in {10,20,...,90}
|
||||
}
|
||||
{
|
||||
\ifthenelse{\i=50}{
|
||||
\draw[black]
|
||||
({#1 + \cdscalefn(\n + \i / 100)}, #2) --
|
||||
({#1 + \cdscalefn(\n + \i / 100)}, #2 + 0.2);
|
||||
\ifthenelse{\n=1}{
|
||||
\draw
|
||||
({#1 + \cdscalefn(\n + \i / 100)}, #2 + 0.2)
|
||||
node [above] {1.5};
|
||||
}{}
|
||||
} {
|
||||
\ifthenelse{
|
||||
\i=10 \OR \i=20 \OR \i=30 \OR \i=40 \OR
|
||||
\i=60 \OR \i=70 \OR \i=80 \OR \i=90
|
||||
}{
|
||||
\draw[black]
|
||||
({#1 + \cdscalefn(\n + \i / 100)}, #2) --
|
||||
({#1 + \cdscalefn(\n + \i / 100)}, #2 + 0.15);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \cdscalefn(\n + \i / 100)}, #2) --
|
||||
({#1 + \cdscalefn(\n + \i / 100)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\newcommand{\ciscale}[3]{
|
||||
\draw[black] ({#1}, #2) -- ({#1 + \sliderulewidth}, #2);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.9);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1}, #2 + 0.7);
|
||||
\draw[black] ({#1 + \sliderulewidth}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.7);
|
||||
|
||||
|
||||
\draw ({#1 - 0.1}, #2 + 0.5) node[left] {#3};
|
||||
|
||||
% Numbers and marks
|
||||
\foreach \i in {1,...,10}{
|
||||
\draw[black]
|
||||
({#1 + \ciscalefn(\i)}, #2) --
|
||||
({#1 + \ciscalefn(\i)}, #2 + 0.3)
|
||||
node[above] {\ifthenelse{\i=10}{1}{\ifthenelse{\i=0}{0}{.\i}}};
|
||||
}
|
||||
|
||||
% Submarks 1 - 9
|
||||
\foreach \n in {1, ..., 9} {
|
||||
\ifthenelse{\n<3}{
|
||||
\foreach \i in {5,10,...,95}
|
||||
} {
|
||||
\foreach \i in {10,20,...,90}
|
||||
}
|
||||
{
|
||||
\ifthenelse{\i=50}{
|
||||
\draw[black]
|
||||
({#1 + \ciscalefn(\n + \i / 100)}, #2) --
|
||||
({#1 + \ciscalefn(\n + \i / 100)}, #2 + 0.2);
|
||||
\ifthenelse{\n=1}{
|
||||
\draw
|
||||
({#1 + \ciscalefn(\n + \i / 100)}, #2 + 0.2)
|
||||
node [above] {1.5};
|
||||
}{}
|
||||
} {
|
||||
\ifthenelse{
|
||||
\i=10 \OR \i=20 \OR \i=30 \OR \i=40 \OR
|
||||
\i=60 \OR \i=70 \OR \i=80 \OR \i=90
|
||||
}{
|
||||
\draw[black]
|
||||
({#1 + \ciscalefn(\n + \i / 100)}, #2) --
|
||||
({#1 + \ciscalefn(\n + \i / 100)}, #2 + 0.15);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \ciscalefn(\n + \i / 100)}, #2) --
|
||||
({#1 + \ciscalefn(\n + \i / 100)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\newcommand{\kscale}[3]{
|
||||
\draw[black] ({#1}, #2) -- ({#1 + \sliderulewidth}, #2);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.9);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1}, #2 + 0.7);
|
||||
\draw[black] ({#1 + \sliderulewidth}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.7);
|
||||
|
||||
|
||||
\draw ({#1 - 0.1}, #2 + 0.5) node[left] {#3};
|
||||
|
||||
% Numbers and marks 1 - 9
|
||||
\foreach \i in {1,...,9}{
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(\i)}, #2) --
|
||||
({#1 + \kscalefn(\i)}, #2 + 0.3)
|
||||
node[above] {\i};
|
||||
}
|
||||
% Numbers and marks 10 - 90
|
||||
\foreach \i in {1,..., 9}{
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(10 * \i)}, #2) --
|
||||
({#1 + \kscalefn(10 * \i)}, #2 + 0.3)
|
||||
node[above] {\ifthenelse{\i=10}{1}{\i}};
|
||||
}
|
||||
% Numbers and marks 100 - 1000
|
||||
\foreach \i in {1,..., 10}{
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(100 * \i)}, #2) --
|
||||
({#1 + \kscalefn(100 * \i)}, #2 + 0.3)
|
||||
node[above] {\ifthenelse{\i=10}{1}{\i}};
|
||||
}
|
||||
|
||||
% Submarks 1 - 9
|
||||
\foreach \n in {1, ..., 9} {
|
||||
\ifthenelse{\n<4}{
|
||||
\foreach \i in {1,..., 9}
|
||||
} {
|
||||
\foreach \i in {2,4,6,8}
|
||||
}
|
||||
{
|
||||
\ifthenelse{\i=5}{
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(\n + \i / 10)}, #2) --
|
||||
({#1 + \kscalefn(\n + \i / 10)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(\n + \i / 10)}, #2) --
|
||||
({#1 + \kscalefn(\n + \i / 10)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
% Submarks 10 - 90
|
||||
\foreach \n in {10,20,...,90} {
|
||||
\ifthenelse{\n<40}{
|
||||
\foreach \i in {1,..., 9}
|
||||
} {
|
||||
\foreach \i in {2,4,6,8}
|
||||
}
|
||||
{
|
||||
\ifthenelse{\i=5}{
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(\n + \i)}, #2) --
|
||||
({#1 + \kscalefn(\n + \i)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(\n + \i)}, #2) --
|
||||
({#1 + \kscalefn(\n + \i)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
% Submarks 100 - 1000
|
||||
\foreach \n in {100,200,...,900} {
|
||||
\ifthenelse{\n<400}{
|
||||
\foreach \i in {10,20,...,90}
|
||||
} {
|
||||
\foreach \i in {20,40,60,80}
|
||||
}
|
||||
{
|
||||
\ifthenelse{\i=50}{
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(\n + \i)}, #2) --
|
||||
({#1 + \kscalefn(\n + \i)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \kscalefn(\n + \i)}, #2) --
|
||||
({#1 + \kscalefn(\n + \i)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\newcommand{\lscale}[3]{
|
||||
\draw[black] ({#1}, #2) -- ({#1 + \sliderulewidth}, #2);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.9);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1}, #2 + 0.7);
|
||||
\draw[black] ({#1 + \sliderulewidth}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.7);
|
||||
|
||||
|
||||
\draw ({#1 - 0.1}, #2 + 0.5) node[left] {#3};
|
||||
|
||||
% Numbers and marks
|
||||
\foreach \i in {0,..., 10}{
|
||||
\draw[black]
|
||||
({#1 + \lscalefn(\i / 10)}, #2) --
|
||||
({#1 + \lscalefn(\i / 10)}, #2 + 0.3)
|
||||
node[above] {\ifthenelse{\i=10}{1}{\ifthenelse{\i=0}{0}{.\i}}};
|
||||
}
|
||||
|
||||
% Submarks
|
||||
\foreach \n in {0, ..., 9} {
|
||||
\foreach \i in {1,...,19} {
|
||||
\ifthenelse{\i=10}{
|
||||
\draw[black]
|
||||
({#1 + \lscalefn((\n + (\i / 20))/10)}, #2) --
|
||||
({#1 + \lscalefn((\n + (\i / 20))/10)}, #2 + 0.2);
|
||||
} {
|
||||
\ifthenelse{
|
||||
\i=1 \OR \i=3 \OR \i=5 \OR \i=7 \OR
|
||||
\i=9 \OR \i=11 \OR \i=13 \OR \i=15 \OR
|
||||
\i=17 \OR \i=19
|
||||
}{
|
||||
\draw[black]
|
||||
({#1 + \lscalefn((\n + (\i / 20))/10)}, #2) --
|
||||
({#1 + \lscalefn((\n + (\i / 20))/10)}, #2 + 0.1);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \lscalefn((\n + (\i / 20))/10)}, #2) --
|
||||
({#1 + \lscalefn((\n + (\i / 20))/10)}, #2 + 0.15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\newcommand{\tscale}[3]{
|
||||
\draw[black] ({#1}, #2) -- ({#1 + \sliderulewidth}, #2);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.9);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1}, #2 + 0.7);
|
||||
\draw[black] ({#1 + \sliderulewidth}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.7);
|
||||
|
||||
% First line
|
||||
\draw[black] ({#1}, #2) -- ({#1}, #2 + 0.2);
|
||||
|
||||
|
||||
\draw ({#1 - 0.1}, #2 + 0.5) node[left] {#3};
|
||||
|
||||
% Numbers and marks 6 - 10
|
||||
\foreach \i in {6,...,9,10,15,...,45}{
|
||||
\draw[black]
|
||||
({#1 + \tscalefn(\i)}, #2) --
|
||||
({#1 + \tscalefn(\i)}, #2 + 0.3)
|
||||
node[above] {\i};
|
||||
}
|
||||
|
||||
% Submarks 6 - 10
|
||||
\foreach \n in {6, ..., 9} {
|
||||
\foreach \i in {1,...,9}{
|
||||
\ifthenelse{\i=5}{
|
||||
\draw[black]
|
||||
({#1 + \tscalefn(\n + \i / 10)}, #2) --
|
||||
({#1 + \tscalefn(\n + \i / 10)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \tscalefn(\n + \i / 10)}, #2) --
|
||||
({#1 + \tscalefn(\n + \i / 10)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
% Submarks 15 - 45
|
||||
\foreach \n in {10, 15, ..., 40} {
|
||||
\foreach \i in {1,...,24}{
|
||||
\ifthenelse{
|
||||
\i=5 \OR \i=10 \OR \i=15 \OR \i=20
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \tscalefn(\n + \i / 5)}, #2) --
|
||||
({#1 + \tscalefn(\n + \i / 5)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \tscalefn(\n + \i / 5)}, #2) --
|
||||
({#1 + \tscalefn(\n + \i / 5)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\newcommand{\sscale}[3]{
|
||||
\draw[black] ({#1}, #2) -- ({#1 + \sliderulewidth}, #2);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.9);
|
||||
\draw[black] ({#1}, #2 + 0.9) -- ({#1}, #2 + 0.7);
|
||||
\draw[black] ({#1 + \sliderulewidth}, #2 + 0.9) -- ({#1 + \sliderulewidth}, #2 + 0.7);
|
||||
|
||||
% First line
|
||||
\draw[black] ({#1}, #2) -- ({#1}, #2 + 0.2);
|
||||
|
||||
|
||||
\draw ({#1 - 0.1}, #2 + 0.5) node[left] {#3};
|
||||
|
||||
% Numbers and marks
|
||||
\foreach \i in {6,...,9,10,15,...,30,40,50,...,60,90}{
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\i)}, #2) --
|
||||
({#1 + \sscalefn(\i)}, #2 + 0.3)
|
||||
node[above] {\i};
|
||||
}
|
||||
|
||||
% Submarks 6 - 10
|
||||
\foreach \n in {6, ..., 9} {
|
||||
\foreach \i in {1,...,9}{
|
||||
\ifthenelse{\i=5}{
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\n + \i / 10)}, #2) --
|
||||
({#1 + \sscalefn(\n + \i / 10)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\n + \i / 10)}, #2) --
|
||||
({#1 + \sscalefn(\n + \i / 10)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
% Submarks 15 - 30
|
||||
\foreach \n in {10, 15, ..., 25} {
|
||||
\foreach \i in {1,...,24}{
|
||||
\ifthenelse{
|
||||
\i=5 \OR \i=10 \OR \i=15 \OR \i=20
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\n + \i / 5)}, #2) --
|
||||
({#1 + \sscalefn(\n + \i / 5)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\n + \i / 5)}, #2) --
|
||||
({#1 + \sscalefn(\n + \i / 5)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
% Submarks 30
|
||||
\foreach \n in {30} {
|
||||
\foreach \i in {1,...,19}{
|
||||
\ifthenelse{
|
||||
\i=2 \OR \i=4 \OR \i=6 \OR \i=8 \OR
|
||||
\i=10 \OR \i=12 \OR \i=14 \OR \i=16 \OR
|
||||
\i=18
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\n + \i / 2)}, #2) --
|
||||
({#1 + \sscalefn(\n + \i / 2)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\n + \i / 2)}, #2) --
|
||||
({#1 + \sscalefn(\n + \i / 2)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
% Submarks 40 - 50
|
||||
\foreach \n in {40, 50} {
|
||||
\foreach \i in {1,...,9}{
|
||||
\ifthenelse{
|
||||
\i=5 \OR \i=10 \OR \i=15 \OR \i=20
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\n + \i)}, #2) --
|
||||
({#1 + \sscalefn(\n + \i)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(\n + \i)}, #2) --
|
||||
({#1 + \sscalefn(\n + \i)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
% Submarks 60
|
||||
\foreach \i in {1,...,10}{
|
||||
\ifthenelse{
|
||||
\i=5 \OR \i=10
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(60 + \i * 2)}, #2) --
|
||||
({#1 + \sscalefn(60 + \i * 2)}, #2 + 0.2);
|
||||
} {
|
||||
\draw[black]
|
||||
({#1 + \sscalefn(60 + \i * 2)}, #2) --
|
||||
({#1 + \sscalefn(60 + \i * 2)}, #2 + 0.1);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.0.4
|
||||
\documentclass[solutions]{ormc_handout}
|
||||
\documentclass[solutions]{../../resources/ormc_handout}
|
||||
\usepackage{adjustbox}
|
||||
|
||||
\begin{document}
|
||||
|
@ -1,8 +1,6 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.0.6
|
||||
\documentclass[solutions]{ormc_handout}
|
||||
\documentclass[solutions]{../../resources/ormc_handout}
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
@ -1,10 +1,8 @@
|
||||
% https://git.betalupi.com/Mark/latex-packages
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
% Last built with version 1.1.0
|
||||
\documentclass[
|
||||
solutions
|
||||
]{ormc_handout}
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\usepackage{subfiles}
|
||||
\usepackage{graphicx}
|
||||
|
159
Misc/Warm-Ups/electician.tex
Executable file
159
Misc/Warm-Ups/electician.tex
Executable file
@ -0,0 +1,159 @@
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
\documentclass[
|
||||
nosolutions,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
% 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}
|
||||
}
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
{The Electrician's Warm-Up}
|
||||
{Prepared by Mark on \today}
|
||||
|
||||
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}
|
||||
|
||||
When a switch is pointing up, it is in the \say{A} state. When it is pointing down, it is in the \say{B} state. Each circle represents a terminal on the switch, and lines represent electrical connections.
|
||||
|
||||
\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. Toggling either switch should toggle the single lamp in the middle. Which switches should Ivan use, and how should he connect their terminals?
|
||||
|
||||
\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}
|
98
Misc/Warm-Ups/raid.tex
Executable file
98
Misc/Warm-Ups/raid.tex
Executable file
@ -0,0 +1,98 @@
|
||||
% use [nosolutions] flag to hide solutions.
|
||||
% use [solutions] flag to show solutions.
|
||||
\documentclass[
|
||||
nosolutions,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../resources/ormc_handout}
|
||||
|
||||
\usepackage{tikz}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
{The Sysadmin's Warm-Up}
|
||||
{Prepared by Mark on \today}
|
||||
|
||||
|
||||
Most of you have seen a hard drive. Many have touched one, and a lucky few have poked around inside one. These devices have two interesting properties:
|
||||
|
||||
\begin{enumerate}
|
||||
\item They hold valuable data
|
||||
\item They eventually fail
|
||||
\end{enumerate}
|
||||
|
||||
Needless to say, this is a problem. \\
|
||||
We need to design a system that allows hard drives to fail without data loss.
|
||||
|
||||
\definition{}
|
||||
You can think of a hard drive as a long string of bits. \\
|
||||
Assume all hard drives can store 1 TiB of data.
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
|
||||
\node[above] at (1/2, 0) {Drive A};
|
||||
\draw (0cm, 0cm) -- (0cm, -3cm);
|
||||
\draw (1cm, 0cm) -- (1cm, -3cm);
|
||||
\foreach \i in {0,...,-6} {
|
||||
\draw (0cm,\i cm / 2) -- (1cm ,\i cm / 2);
|
||||
}
|
||||
|
||||
\node at (1/2, - 1 / 4) {1};
|
||||
\node at (1/2, - 3 / 4) {1};
|
||||
\node at (1/2, - 5 / 4) {0};
|
||||
\node at (1/2, - 7 / 4) {...};
|
||||
\node at (1/2, - 9 / 4) {1};
|
||||
\node at (1/2, -11 / 4) {0};
|
||||
|
||||
|
||||
\node[above] at (5/2, 0) {Drive B};
|
||||
\draw (2cm, 0cm) -- (2cm, -3cm);
|
||||
\draw (3cm, 0cm) -- (3cm, -3cm);
|
||||
\foreach \i in {0,...,-6} {
|
||||
\draw (2cm,\i cm / 2) -- (3cm ,\i cm / 2);
|
||||
}
|
||||
|
||||
\node at (5/2, - 1 / 4) {0};
|
||||
\node at (5/2, - 3 / 4) {1};
|
||||
\node at (5/2, - 5 / 4) {0};
|
||||
\node at (5/2, - 7 / 4) {...};
|
||||
\node at (5/2, - 9 / 4) {0};
|
||||
\node at (5/2, -11 / 4) {1};
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\problem{}
|
||||
Suppose we have two hard drives. How can we arrange our data so that...
|
||||
\begin{enumerate}
|
||||
\item We get 1 TiB of usable storage
|
||||
\item We lose no data if any one drive fails
|
||||
\end{enumerate}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Suppose we have three hard drives. How can we arrange our data so that...
|
||||
\begin{enumerate}
|
||||
\item We get 2 TiB of usable storage
|
||||
\item We lose no data if any one drive fails
|
||||
\end{enumerate}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Suppose we have five hard drives. How can we arrange our data so that...
|
||||
\begin{enumerate}
|
||||
\item We get 3 TiB of usable storage
|
||||
\item We lose no data if any two drives fail
|
||||
\end{enumerate}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Write a general solution to this problem, using $n$ drives and providing $s$ TiB of storage. \\
|
||||
How many failures will such an array be able to tolerate?
|
||||
|
||||
\vfill
|
||||
\end{document}
|
30
README.md
30
README.md
@ -1,7 +1,6 @@
|
||||
# ORMC Handouts
|
||||
|
||||
This repository contains all the handouts I've written for the [ORMC](https://circles.math.ucla.edu/circles/). Most of them are built using [these](https://git.betalupi.com/Mark/latex) packages.
|
||||
|
||||
This repository contains all the handouts I've written for the [ORMC](https://circles.math.ucla.edu/circles/).
|
||||
|
||||
If you are not affiliated with the ORMC, ask for permission before using these.
|
||||
|
||||
@ -11,4 +10,29 @@ Handouts are sorted by the class they're for:
|
||||
- [`./Intermediate`](./Intermediate/): Grades 5 - 9
|
||||
- [`./Advanced`](./Advanced): Grades 9 - 12
|
||||
|
||||
These grade levels are estimates.
|
||||
Grade levels are estimates.
|
||||
|
||||
## Usage
|
||||
|
||||
Most handouts use a custom document class. If you move any files out of this repository, you'll need to change a few things for the handout to compile:
|
||||
1. Download [`./resources/ormc_handout.cls`](./resources/ormc_handout.cls).
|
||||
2. Put it in the same directory as the handout.
|
||||
3. Fix the include path at the top of the handout.
|
||||
|
||||
Usually, you'll need to replace
|
||||
|
||||
```latex
|
||||
\documentclass[
|
||||
solutions
|
||||
]{../../resources/ormc_handout}
|
||||
```
|
||||
|
||||
with
|
||||
|
||||
```latex
|
||||
\documentclass[
|
||||
solutions
|
||||
]{ormc_handout}
|
||||
```
|
||||
|
||||
**Warning:** As of now, `ormc_handout.cls` does not work with hyperref.
|
441
resources/ormc_handout.cls
Normal file
441
resources/ormc_handout.cls
Normal file
@ -0,0 +1,441 @@
|
||||
\NeedsTeXFormat{LaTeX2e}
|
||||
\ProvidesClass{ormc_handout}[2022/05/07 1.1.0 ORMC Handout]
|
||||
|
||||
|
||||
% Boolean that determines solution behavior.
|
||||
% If false, solutions and instructor notes are hidden.
|
||||
\newif{\ifsolutions}
|
||||
\solutionstrue
|
||||
|
||||
% Boolean that determines object numbering
|
||||
% If true, the same counter is used for all objects.
|
||||
\newif{\ifsinglenumbering}
|
||||
\singlenumberingfalse
|
||||
|
||||
% Boolean. If true, don't number pages.
|
||||
\newif{\ifnopagenumber}
|
||||
\nopagenumberfalse
|
||||
|
||||
% Declare and parse arguments
|
||||
\DeclareOption{solutions}{\solutionstrue}
|
||||
\DeclareOption{nosolutions}{\solutionsfalse}
|
||||
\DeclareOption{singlenumbering}{\singlenumberingtrue}
|
||||
\DeclareOption{nopagenumber}{\nopagenumbertrue}
|
||||
\DeclareOption*{\ClassWarning{ormc_handout}{\CurrentOption ignored}}
|
||||
\ProcessOptions\relax
|
||||
|
||||
% Based on article class
|
||||
\LoadClass{article}
|
||||
\makeatletter % Allow commands with @ (\makeatother is at end of this file)
|
||||
|
||||
\newcommand\sbullet[1][.5]{\mathbin{\vcenter{\hbox{\scalebox{#1}{$\bullet$}}}}}
|
||||
|
||||
\renewcommand{\labelitemi}{$\sbullet$}
|
||||
\renewcommand{\labelitemii}{$\cdot$}
|
||||
|
||||
|
||||
% Hack for command-line arguments.
|
||||
% To force a build with solutions, run
|
||||
% latexmk
|
||||
% -synctex=1
|
||||
% -interaction=nonstopmode
|
||||
% -file-line-error
|
||||
% -outdir=%OUTDIR%
|
||||
% -xelatex
|
||||
% -jobname=%DOCFILE%.sol
|
||||
% -pdfxelatex="xelatex %O \"\\def\\argYesSolutions{1}\\input{%S}\""
|
||||
% %DOC%
|
||||
%
|
||||
% Or, make a new file with the contents
|
||||
% \def\argYesSolutions{1}\input{<target file>}
|
||||
% and build that with latex.
|
||||
\ifdefined\argYesSolutions
|
||||
\solutionstrue
|
||||
\else
|
||||
\ifdefined\argNoSolutions
|
||||
\solutionsfalse
|
||||
\fi
|
||||
\fi
|
||||
|
||||
|
||||
|
||||
|
||||
%%% PACKAGES %%%
|
||||
|
||||
|
||||
% Set up page geometry.
|
||||
% MUST BE DONE FIRST!
|
||||
\RequirePackage{geometry}
|
||||
\geometry{
|
||||
paper = letterpaper,
|
||||
top = 25mm,
|
||||
bottom = 30mm,
|
||||
left = 30mm,
|
||||
right = 30mm,
|
||||
headheight = 75mm,
|
||||
footskip = 15mm,
|
||||
headsep = 75mm,
|
||||
}
|
||||
|
||||
\RequirePackage{enumitem} % list customization
|
||||
\RequirePackage{xparse} % Provides powerful macros via \NewDocumentCommand
|
||||
\RequirePackage{xcolor} % For colored text
|
||||
\RequirePackage{tcolorbox} % For solution boxes
|
||||
\RequirePackage{tikz} % Used by \boxlinehack
|
||||
\RequirePackage{comment} % Used to hide solutions
|
||||
\RequirePackage{fancyhdr} % Header/Footer customization
|
||||
\RequirePackage{adjustbox} % Used for title
|
||||
|
||||
\RequirePackage[
|
||||
left = ``,
|
||||
right = '',
|
||||
leftsub = `,
|
||||
rightsub = '
|
||||
]{dirtytalk}
|
||||
|
||||
% Not used by this class, but likely to be used in documents
|
||||
\RequirePackage{amsmath}
|
||||
\RequirePackage{amssymb}
|
||||
\RequirePackage{multicol}
|
||||
\RequirePackage{subfiles}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
%%% CONFIG %%%
|
||||
|
||||
|
||||
% No paragraph indentation, no list item spacing,
|
||||
% raggedright layout (hyphenation is excessive).
|
||||
\setlength{\parindent}{0mm}
|
||||
\setlist{noitemsep, topsep=0mm}
|
||||
\raggedright
|
||||
|
||||
% Use symbols instead of numbers for footnotes
|
||||
\renewcommand*{\thefootnote}{\arabic{footnote}}
|
||||
|
||||
% One space after a period.
|
||||
\frenchspacing
|
||||
|
||||
|
||||
% Fancyhdr setup
|
||||
\pagestyle{fancy}
|
||||
\fancyhf{}
|
||||
\renewcommand{\headrulewidth}{0mm}
|
||||
|
||||
\ifnopagenumber
|
||||
\else
|
||||
\fancyfoot[C]{\thepage}
|
||||
\fi
|
||||
|
||||
|
||||
|
||||
|
||||
%%% COMMANDS %%%
|
||||
|
||||
|
||||
% Make a heading.
|
||||
% Arguments:
|
||||
%
|
||||
% First: Top-left text
|
||||
% Second: Top-right text
|
||||
% Both are optional, but should only be provided TOGETHER.
|
||||
%
|
||||
% Third: Title
|
||||
% Forth: author
|
||||
\RenewDocumentCommand{\maketitle}{ d<> d<> m m } {
|
||||
\begin{adjustbox}{minipage=0.7\textwidth, margin=0pt \smallskipamount,center}
|
||||
\begin{center}
|
||||
|
||||
\IfNoValueF{#1}{\textsc{#1}} \hfill \IfNoValueF{#2}{\textsc{#2}} \\
|
||||
\rule{\linewidth}{0.2mm}\\
|
||||
|
||||
\huge
|
||||
#3 \\
|
||||
\normalsize
|
||||
\vspace{1ex}
|
||||
#4
|
||||
\rule{\linewidth}{0.2mm} \\
|
||||
|
||||
% Instructor's handout warning
|
||||
\ifsolutions
|
||||
\begin{tcolorbox}[
|
||||
colback=white,
|
||||
colframe=red
|
||||
]
|
||||
\begin{center}
|
||||
\large
|
||||
\textcolor{red}{
|
||||
\textbf{Instructor's Handout}
|
||||
} \\
|
||||
\normalsize
|
||||
\end{center}
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
\textcolor{red}{This file contains solutions and notes.}
|
||||
|
||||
\textcolor{red}{Compile with the ``nosolutions'' flag before distributing.}
|
||||
\end{tcolorbox}
|
||||
\fi
|
||||
|
||||
\end{center}
|
||||
\end{adjustbox}
|
||||
}
|
||||
|
||||
|
||||
% Helper command that creates a label with custom text.
|
||||
% First arg: label name
|
||||
% Second arg: custom text
|
||||
\newcommand{\customlabel}[2]{%
|
||||
\protected@write \@auxout {}{
|
||||
\string \newlabel {#1}{{#2}{}}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
% Commands for problems, theorems, and definitions
|
||||
%
|
||||
% Each of these take two arguments. For example:
|
||||
%
|
||||
% \problem{} makes an unnamed problem
|
||||
% \problem{Division} makes a named problem
|
||||
% \problem{}<gcd>
|
||||
% makes a problem and a label "problem:gcd"
|
||||
% that gives text "Problem X" when referenced.
|
||||
|
||||
\newcounter{section_counter}
|
||||
\newcounter{problempartcounter}
|
||||
|
||||
\ifsinglenumbering
|
||||
\newcounter{object_counter}
|
||||
|
||||
\def\problemcounter{object_counter}
|
||||
\def\theoremcounter{object_counter}
|
||||
\def\definitioncounter{object_counter}
|
||||
\def\examplecounter{object_counter}
|
||||
\def\propositioncounter{object_counter}
|
||||
\else
|
||||
\newcounter{problem_counter}
|
||||
\newcounter{theorem_counter}
|
||||
\newcounter{definition_counter}
|
||||
\newcounter{example_counter}
|
||||
\newcounter{proposition_counter}
|
||||
|
||||
\def\problemcounter{problem_counter}
|
||||
\def\theoremcounter{theorem_counter}
|
||||
\def\definitioncounter{definition_counter}
|
||||
\def\examplecounter{example_counter}
|
||||
\def\propositioncounter{proposition_counter}
|
||||
\fi
|
||||
|
||||
|
||||
% Generic object command.
|
||||
% First arg: counter name (mandatory)
|
||||
% Second arg: object type (optional)
|
||||
% Third arg: object title (mandatory, can be empty)
|
||||
%
|
||||
% If the second argument is ommited, the counter is hidden
|
||||
% and only the object title is shown. For example:
|
||||
% \@object{counter}[Problem]{Example Problem} -> Problem 1: Example Problem
|
||||
% \@object{counter}{Example Problem} -> Example Problem
|
||||
%
|
||||
% Only used internally (See following definitions)
|
||||
\NewDocumentCommand{\@object}{ m d[] m}{
|
||||
\stepcounter{#1}
|
||||
\vspace{3mm}
|
||||
\IfNoValueTF{#2} {
|
||||
{\bf\normalsize #3}
|
||||
} {
|
||||
{\bf\normalsize #2 \arabic{#1}:\IfNoValueF{#3}{ #3}}
|
||||
}
|
||||
}
|
||||
|
||||
% Generic object.
|
||||
% Does the same thing as \problem, \theorem, etc, but with no counter.
|
||||
\NewDocumentCommand{\generic}{ m d<> }{
|
||||
\vspace{3mm}
|
||||
{\bf\normalsize #1} \\*
|
||||
|
||||
\IfNoValueF{#2}{
|
||||
\customlabel{#2}{#1}
|
||||
}
|
||||
}
|
||||
|
||||
% If not starred, text is "Part X: <title>"
|
||||
% If starred, text is "<title>"
|
||||
\RenewDocumentCommand{\section}{ s m d<> }{
|
||||
\stepcounter{section_counter}
|
||||
\vspace{8mm}
|
||||
\IfBooleanTF{#1}{
|
||||
{\bf\Large \hfill #2 \hfill}
|
||||
\IfNoValueF{#3}{\customlabel{#3}#2} \\*
|
||||
} {
|
||||
{\bf\Large \hfill Part \arabic{section_counter}\IfNoValueF{#2}{: #2} \hfill}
|
||||
\IfNoValueF{#3}{\customlabel{#3}Part \arabic{section_counter}} \\*
|
||||
}
|
||||
\vspace{2mm}
|
||||
}
|
||||
|
||||
|
||||
\RenewDocumentCommand{\paragraph}{}{
|
||||
\hspace{1cm}
|
||||
}
|
||||
|
||||
\NewDocumentCommand{\problem}{ m d<> }{
|
||||
\setcounter{problempartcounter}{0}
|
||||
|
||||
\@object{\problemcounter}[Problem]{#1}
|
||||
\IfNoValueF{#2}{
|
||||
\customlabel{#2}{Problem \arabic{\problemcounter}}
|
||||
\customlabel{NUM:#2}{\arabic{\problemcounter}}
|
||||
} \\*
|
||||
}
|
||||
|
||||
\NewDocumentCommand{\problempart}{ m d<> }{
|
||||
\@object{problempartcounter}[Part]{#1}
|
||||
\IfNoValueF{#2}{
|
||||
\customlabel
|
||||
{#2}
|
||||
{Problem \arabic{\problemcounter}\alph{problempartcounter}}
|
||||
\customlabel{NUM:#2}{\arabic{\problemcounter}\alph{problempartcounter}}
|
||||
} \\*
|
||||
}
|
||||
|
||||
\NewDocumentCommand{\definition}{ m d<> }{
|
||||
\@object{\definitioncounter}[Definition]{#1}
|
||||
\IfNoValueF{#2}{
|
||||
\customlabel{#2}{Definition \arabic{\definitioncounter}}
|
||||
\customlabel{NUM:#2}{\arabic{\definitioncounter}}
|
||||
} \\*
|
||||
}
|
||||
|
||||
\NewDocumentCommand{\theorem}{ m d<> }{
|
||||
\@object{\theoremcounter}[Theorem]{#1}
|
||||
\IfNoValueF{#2}{
|
||||
\customlabel{#2}{Theorem \arabic{\theoremcounter}}
|
||||
\customlabel{NUM:#2}{\arabic{\theoremcounter}}
|
||||
} \\*
|
||||
}
|
||||
|
||||
\NewDocumentCommand{\proposition}{ m d<> }{
|
||||
\@object{\propositioncounter}[Proposition]{#1}
|
||||
\IfNoValueF{#2}{
|
||||
\customlabel{#2}{Proposition \arabic{\propositioncounter}}
|
||||
\customlabel{NUM:#2}{\arabic{\propositioncounter}}
|
||||
} \\*
|
||||
}
|
||||
|
||||
\NewDocumentCommand{\example}{ m d<> }{
|
||||
\@object{\examplecounter}[Example]{#1}
|
||||
\IfNoValueF{#2}{
|
||||
\customlabel{#2}{Example \arabic{\examplecounter}}
|
||||
\customlabel{NUM:#2}{\arabic{\examplecounter}}
|
||||
} \\*
|
||||
}
|
||||
|
||||
|
||||
% Solution environment.
|
||||
% examplesolution environment is always shown (useful for example problems)
|
||||
% solution environments do the same thing, but are hidden when the [nosolutions] flag is passed.
|
||||
\newenvironment{examplesolution} {
|
||||
\begin{tcolorbox}[
|
||||
colback=white,
|
||||
colframe=gray!75!black,
|
||||
title={\textbf{Example Solution}}
|
||||
]
|
||||
}{
|
||||
\end{tcolorbox}
|
||||
}
|
||||
|
||||
\def\ORMCbgcolor{white}
|
||||
|
||||
% \if isn't parsed inside of LaTeX environents,
|
||||
% so we have to use the comment package.
|
||||
\newenvironment{@shown_solution} {
|
||||
\def\ORMCbgcolor{red!5!white}
|
||||
\begin{tcolorbox}[
|
||||
colback=red!5!white,
|
||||
colframe=red!75!black,
|
||||
title={\textbf{Solution}}
|
||||
]
|
||||
\raggedright
|
||||
}{
|
||||
\end{tcolorbox}
|
||||
}
|
||||
|
||||
\newenvironment{@shown_note} {
|
||||
\def\ORMCbgcolor{cyan!5!white}
|
||||
\begin{tcolorbox}[
|
||||
colback=cyan!5!white,
|
||||
colframe=cyan!75!black,
|
||||
title={\textbf{Note for Instructors}}
|
||||
]
|
||||
\raggedright
|
||||
}{
|
||||
\end{tcolorbox}
|
||||
}
|
||||
|
||||
% tcolorbox only give us two sections.
|
||||
% This macro makes a macro \linehack that draws
|
||||
% lines across a tcolorbox.
|
||||
%
|
||||
% Inside every environment that needs a
|
||||
% \linehack macro, put \@makelinehack{color}.
|
||||
\newcommand{\@makelinehack}[1]{
|
||||
\newcommand{\linehack}{
|
||||
\begin{tikzpicture}
|
||||
\path[use as bounding box]
|
||||
(0, 0)
|
||||
--
|
||||
(\linewidth, 0);
|
||||
|
||||
\draw[
|
||||
color=#1,
|
||||
dashed,
|
||||
dash phase=1mm
|
||||
]
|
||||
(
|
||||
0 - \kvtcb@leftlower-\kvtcb@boxsep,
|
||||
0
|
||||
) -- (
|
||||
\linewidth + \kvtcb@rightlower + \kvtcb@boxsep,
|
||||
0
|
||||
);
|
||||
\end{tikzpicture} \\
|
||||
}
|
||||
}
|
||||
|
||||
\ifsolutions
|
||||
\newenvironment{solution}{
|
||||
\@makelinehack{red!75!black}
|
||||
\begin{@shown_solution}
|
||||
} {
|
||||
\end{@shown_solution}
|
||||
}
|
||||
\newenvironment{instructornote}{
|
||||
\@makelinehack{cyan!75!black}
|
||||
\begin{@shown_note}
|
||||
} {
|
||||
\end{@shown_note}
|
||||
}
|
||||
\else
|
||||
\excludecomment{solution}
|
||||
\excludecomment{instructornote}
|
||||
\fi
|
||||
|
||||
|
||||
\NewDocumentCommand{\note}{ d<> m }{
|
||||
\IfNoValueTF{#1} {
|
||||
\textcolor{gray}{#2} \\
|
||||
} {
|
||||
\textcolor{gray}{\textit{#1:} #2} \\
|
||||
}
|
||||
}
|
||||
|
||||
\NewDocumentCommand{\hint}{ m }{
|
||||
\note<Hint>{#1}
|
||||
}
|
||||
|
||||
\makeatother
|
Loading…
x
Reference in New Issue
Block a user