International Standard Book Numbers or ISBNs (the older, 10-digit kind, not the newer 13-digit kind starting with 978) have an interesting way of detecting errors made in writing down the numbers. The number at the top of the image above is an example of what I mean. The process works like this:

- Circle the right-hand digit. This is the check digit. If it’s an “X,” that means 10. In the image above, the check digit (5) is circled in red.
- Copy the other 9 digits, and write 10, 9, 8, 7, 6, 5, 4, 3, 2 underneath them.
- Multiply vertical pairs of numbers, and add up the products. Call this
*S*. For the example above,*S*= 0 + 81 + 24 + 42 + 18 + 40 + 20 + 12 + 0 = 237. - Divide by 11, and call the remainder
*R*. For the example above,*R*= 6. - The check digit should be 0 if
*R*= 0, and 11 −*R*otherwise. If not, something is wrong. For the example above, the check digit is 11 − 6 = 5 (for students familiar with modular arithmetic, we can express this more simply: the check digit should be −*S***mod**11).

This scheme will detect any copying error where a single digit gets changed. Imagine that one of the digits is *A* (ranging from 0 to 9), in the position where it gets multiplied by *N* (ranging from 10 to 2), and *A* gets replaced by a different digit *B* (ranging from 0 to 9). The sum *S* will increase by (*B* − *A*)*N*, which **cannot be a multiple of 11**. Therefore the remainder *R* will change, and the check digit calculated in step 5 will no longer match the circled one.

The ISBN system also spots digits being swapped. Imagine that one of the digits is *A* (ranging from 0 to 9), in the position where it gets multiplied by *N* (ranging from 10 to 2). Another digit is *B* (ranging from 0 to 9, with *B* ≠ *A*), in the position where it gets multiplied by *M* (ranging from 10 to 2, with *M* ≠ *N*). If the digits *A* and *B* are swapped, by a similar argument to the one above, the check digit calculated in step 5 will no longer match the circled one.

A number of similar schemes exist, since the problem of people writing down numbers incorrectly is widespread, and detecting such errors is often worthwhile. Australian Medicare cards, like the one above, operate as follows:

- Ignore the right-hand digit, which is a sequence number. Circle the digit second from the right. This is the check digit. In the image above, the check digit (8) is circled in red.
- Copy the other 8 digits, and write 1, 3, 7, 9, 1, 3, 7, 9 underneath them.
- Multiply vertical pairs of numbers, and add up the products. Call this
*S*. For the example above,*S*= 1 + 6 + 21 + 36 + 5 + 18 + 49 + 72 = 208. - Divide by 10, and call the remainder
*R*. For the example above,*R*= 8. - The check digit should
*R*. For the example above, the check digit is 8.

This scheme will also detect any copying error where a single digit gets changed. Imagine that one of the digits is *A* (ranging from 0 to 9), in the position where it gets multiplied by *N* (1, 3, 7, or 9), and *A* gets replaced by a different digit *B* (ranging from 0 to 9). The sum *S* will increase by (*B* − *A*)*N*, which cannot be a multiple of 10 (this is why 5 is excluded as one of the multiplying numbers). Therefore the remainder *R* will change, and the check digit calculated in step 5 will no longer match the circled one.

However, the Australian Medicare Number scheme only detects some digit swaps. Even if we only worry about swapping adjacent digits, it does not catch all such errors. For example, 1**27**45678**6** and 1**72**45678**6** are both valid. If you imagine that one of the digits is *A* (in the position where it gets multiplied by *N*) and the adjacent digit is *B* (in the position where it gets multiplied by *M*), you can see that sometimes the change in *S* from a swap will be a multiple of 10, leaving the check digit unchanged.

Pingback: List processing in NetLogo: some more examples | Scientific Gems

Pingback: Mathematics in Action: Vehicle Identifications Numbers | Scientific Gems