← Error Detection (Parity Magic Trick)
Grades 2–3 reading level
Error Detection (Parity Magic Trick)
Adapted with AI from the original open resource by CS Unplugged. Nothing is invented — only the reading level changes.
Activity 4
Card Flip Magic—Finding and Fixing Mistakes
Summary
When we save information on a computer, or send it to another computer, we hope it stays the same. But sometimes something goes wrong, and the information gets changed by accident. This activity uses a magic trick to show how we can find out when data (information) has been changed, and how to fix it.
Who This Is For
This is good for math class. Kids will practice counting, and telling odd numbers from even numbers. It works well for kids age 9 and up.
Skills You Will Use
- Counting
- Telling odd numbers from even numbers
What You Need
- 36 "fridge magnet" cards. Each card is colored on one side only.
- A metal board, like a whiteboard, to show the trick.
- Each pair of kids will also need their own set of 36 matching cards, colored on one side.
The Magic Trick
Show the Trick First
Now it's your turn to be a magician!
You will need a pile of matching cards. Each card should have two sides. (You can make these by cutting up cardboard that is colored on one side.) Fridge magnets that are a different color on each side work great for showing this trick to the class.
- Pick a kid to lay out 25 cards in a square. That's 5 cards across and 5 cards down. Some cards should show their colored side, and some should show their plain side, all mixed up.
Then add one more row and one more column, just to make the trick look harder.
These extra cards are the secret to the trick! You must place them so that every row and every column has an even number of colored cards. (Remember: 0 counts as an even number too!)
- Cover your eyes. Have a kid flip over just one card. Now, the row and the column with that flipped card will have an odd number of colored cards. That's how you can find which card was flipped!
Can the kids guess how the trick works?
Teach the Trick to the Kids
- Working in pairs, kids lay out their cards in a 5-by-5 square (5 across, 5 down).
- Count the colored cards in each row and each column. Is the number odd or even? (Remember, 0 is even!)
- Add a 6th card to the end of each row. Place it so the number of colored cards in that row becomes even. This extra card is called a "parity" card.
- Add a 6th row of cards along the bottom too. This makes every column have an even number of colored cards as well.
- Now flip one card over. What do you notice about its row and column? (They will now have an odd number of colored cards!) Parity cards help us know when a mistake has happened.
- Take turns doing the trick for each other!
Try These Extra Challenges
- Try the trick with other things that have two sides or two states — like playing cards, coins (heads or tails), or cards with "0" and "1" on them (like computers use).
- What happens if you flip two cards instead of one? (You can tell something changed, but it's harder to know exactly which two cards were flipped. Sometimes there are two possible answers. If you flip 4 cards, it's even possible all the parity cards look correct — so the mistake might not be caught at all!)
- Look at the bottom right-hand card. If you pick it to make its column correct, will it also make its row correct? (Yes — this always works!)
- In this trick, we made sure each row and column had an even number of colored cards. This is called "even parity." Could we use "odd parity" instead, where each row and column has an odd number? (Yes, this works too. But the bottom right-hand card will only work correctly for both its row and column if the number of rows and the number of columns are both even, or both odd. For example, 5 rows and 9 columns works fine. So does 4 and 6. But 3 rows and 4 columns won't work.)
A Real-Life Example
This same idea — using parity to catch mistakes — is used with book codes! Every published book has a 10-digit code, usually on the back cover. This is called an ISBN (International Standard Book Number). The very last digit of this code is special. It's called a "check digit," and it works just like the parity cards in our trick.
This means that when you order a book using its ISBN, the publisher can check if you made a mistake typing it in. They do this by looking at something called a checksum — a number used to check that everything is correct.
How to Find the Checksum
Multiply the first digit by 10. Multiply the second digit by 9. Multiply the third digit by 8. Keep going like this, all the way down, multiplying the ninth digit by 2. Then add up all these answers together.
For example, take the ISBN 0-13-911991-4:
(0 × 10) + (1 × 9) + (3 × 8) + (9 × 7) + (1 × 6) + (1 × 5) + (9 × 4) + (9 × 3) + (1 × 2) = 172
Next, divide your answer by 11. What is left over (the remainder)?
172 ÷ 11 = 15, remainder 7
If there's no remainder, the checksum is 0. If there is a remainder, subtract it from 11 to get the checksum.
11 − 7 = 4
Now look at the ISBN again. Is 4 the last digit? Yes, it is!
If the last digit had NOT been 4, we would know a mistake was made somewhere.
Sometimes, the checksum comes out to 10. Since 10 needs two digits, we use the letter "X" instead.
Grocery items also use a check digit! It's found in their barcode (called a UPC), like the one on a box of cereal. Barcodes use a different way of calculating the check digit. If a barcode is scanned wrong, the check digit won't match. That's when the scanner beeps, and the checkout person has to scan it again.
Check That Book!
Detective Blockbuster Book Tracking Service, Inc.
We check ISBN checksums for a small fee!
Join our detective agency! Look around your classroom or library for real ISBN codes. Are their checksums correct? Sometimes mistakes really do happen. Here are common types of mistakes:
- A digit's value gets changed.
- Two digits next to each other get swapped.
- An extra digit gets added in.
- A digit gets left out.
Can you find a book with the letter "X" as its checksum? It shouldn't be too hard — about 1 out of every 11 books should have one!
What kinds of mistakes might slip by without being caught? Can you change one digit and still get the same checksum? What if you swap two digits (a mistake people often make while typing)?
What's This All About?
Imagine you're putting $10 into your bank account. The bank worker types in the amount, and it gets sent to a big computer. But what if something interferes with the signal while it's traveling, and the $10 accidentally turns into $1,000? That's not a problem for you — but it's a big problem for the bank!
That's why it's so important to catch mistakes when information is sent from place to place. The computer receiving the information needs to check that nothing got messed up along the way — maybe from electrical interference.
Sometimes, if a mistake happens, the information can just be sent again. But sometimes that's not possible. For example, a disk or tape might get damaged by magnets, heat, or physical harm. Or imagine getting information from a spacecraft far out in space — it would take forever to wait for it to be sent again! (It takes over half an hour for a radio signal to travel from Jupiter to Earth, even when Jupiter is at its closest!)
That's why we need two things: a way to notice when data has been changed by mistake (called error detection), and a way to fix it back to how it should be (called error correction).
The same idea from our card-flipping game is used inside real computers! By arranging bits (computer data) into imaginary rows and columns, and adding parity bits to each row and column, computers can find out not just THAT a mistake happened, but WHERE it happened. Then, the wrong bit gets changed back — and that's error correction in action!
Real computers often use even fancier systems that can catch and fix more than one mistake at a time. In fact, a big part of your computer's hard disk is set aside just for fixing errors! This helps the disk keep working properly, even if parts of it start to fail. These systems work using ideas very similar to our parity trick.
And here's a joke for those who finished this whole activity:
Q: What do you call this: "Pieces of nine, pieces of nine"?
A: A parroty error! (It sounds like "parity error" — but said like a parrot talking!)
Hints and Answers
Mistakes that would NOT be caught are ones where one digit goes up by some amount, and another digit goes down by the same amount. That way, the total sum could still come out the same as before — and the mistake sneaks by unnoticed!
Original licensed under CC BY-NC-SA 4.0. This adaptation is provided free by OER.ai.