\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$. \par The final digit, $n_{10}$, is chosen from $\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\}$ so that: $$ \sum_{i = 1}^{10} (11 - i)n_i \equiv 0 \text{ mod } 11 $$ If $n_{10}$ is equal to 10, it is written as \texttt{X}. \problem{} Only one of the following ISBNs is valid. Which one is it? \begin{itemize} \item \texttt{0-134-54896-2} \item \texttt{0-895-77258-2} \end{itemize} \begin{solution} The first has an inconsistent check digit. \end{solution} \vfill \pagebreak \problem{} Take a valid ISBN-10 and change one digit. Is it possible that you get another valid ISBN-10? \par Provide 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$. \par $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)}$. \par 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? \par This is called a \textit{transposition error}. \begin{solution} Let $n_1n_2...n_{10}$ be a valid ISBN-10. \par 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)}$. \par 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? \par \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? \par If you can, provide an example; if you can't, provide 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$. \par \vspace{3mm} Since $n_i$, $m_i$ $\in \{0, 1, 2, ..., 9\}$, $-9 \leq n_i - m_i \leq 9$. \par \vspace{2mm} Case 0: $i$ is 13 \par This is trivial. \vspace{2mm} Case 1: $i$ is odd \par For the new ISBN to be valid, we need $n_i - m_i \equiv 0 \text{ (mod 10)}$. \par This cannot happen if $n_i \neq m_i$. \vspace{2mm} Case 2: $i$ is even \par For the new ISBN to be valid, we need $3(n_i - m_i) \equiv 0 \text{ (mod 10)}$ \par 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? \par \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\}$. \par The checksum changes by $2(n_{i+1} - n_i)$, and will \par 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. \par Can you find the digit I changed? Can you recover the original ISBN? \begin{solution} Nope, unless you look at the meaning of each digit in the spec. \par If you're unlucky, maybe not even then. \end{solution} \vfill \pagebreak