Hack #38. Calculate Mental Checksums
Computers use checksums to ensure that data was not corrupted in transmission. Now your brain can use a checksum for your mental math, with a few easy techniques.
It's important to have some way to check your mental math that doesn't take as long as solving the problem did originally, and ideally is much shorter. It's easy to check your math for the four basic operations of arithmetic (addition, subtraction, multiplication, and division) by calculating digit sums for the numbers involved. A digit sum is a special kind of checksum or data integrity check. Checksums are used all over the world of computing, from credit cards to ISBNs on books, to downloads you make with your web browser. Now your brain can use them, too.
Finding the digit sum of a number is easy. Just add all the digits of the number together. If the result is greater than 9, add the digits together again. Continue to do so until you have a one-digit result. If the result is 9, reduce it to 0. The result is the digit sum of the original number.1
For example, the digit sum of 381 is 3:
3 + 8 + 1 = 12 1 + 2 = 3
Similarly, the digit sum of 495 is 0:
4 + 9 + 5 = 18 1 + 8 = 9 (same as 0)
A number's digit sum is actually that number modulo 9—in other words, the remainder when that number is divided by 9. See "Calculate Any Weekday" [Hack #43] for a refresher on modulo arithmetic.
This technique is also known as casting out nines. Casting out nines and a similar technique known as casting ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access