Computer Science Outreach Magic

For several months, I always carried a deck of cards in my backpack. I like playing gin rummy as much as anyone, but that's not the reason why. I carried them because I had discovered Computer Science Outreach Magic.

I learned a Computer Science magic trick from cs4fn.org/magic, and I've been hooked ever since. I've performed this trick to much success when manning booths at outreach events and teacher visiting days. It lets you engage people while illustrating a bit of computer science. At the PyLadies' lunch at PyCon '13, Esther Nam convinced me to write a blog post about this card trick I was so excited about. "Lots of people want to know how to demonstrate computer science without a computer!" she said.

Teaching the card trick to Computer Science student volunteers at the Tucson Festival of Books.
Performing the big reveal at a University of Arizona College of Science ceremony.

 That's exactly why I love this trick. It's portable, it's easy, and it doesn't use a computer. It allows people to see an easily digestible example of the logic, discrete math, and information that is at the core of Computer Science. For people who aren't impressed by physical computers or cryptic terminal windows, this can really be a draw.
"[Computer science] is not really about computers—and it's not about computers in the same sense that physics is not really about particle accelerators, and biology is not about microscopes and Petri dishes.... Now the reason that we think computer science is about computers is pretty much the same reason that the Egyptians thought geometry was about surveying instruments: when some field is just getting started and you don't really understand it very well, it's very easy to confuse the essence of what you're doing with the tools that you use." - Hal Abelson (1986)

Here's how I do it:

  1. You need three people: The magician, the assistant, and the learner.
  2. The magician closes her eyes and keeps them closed until the end of the trick.
  3. The learner is given the deck and told to make a four by four matrix of cards with some face up and some face down, randomly distributed.
  4. The assistant takes the deck back and whispers to the learner: "I'm going to make it harder for her and add another row and column". The magician might groan at this point and say "Nooo it's so hard already!!!" The new row and column are added.
  5. The assistant tells the learner to flip one card, and that the magician will tell him which card he flipped. The learner flips one card.
  6. The magician opens her eyes, hovers her hands over the cards, and identifies the flipped card!
  7. The learner is very impressed. While the amazement hasn't worn off, the magician and assistant tell the learner that this method is used to identify errors in computer data. Face up and face down cards are just like the way a computer stores information in 1s and 0s. Perhaps the information is being sent from one computer to another and one of the bits—one of the 1s or 0s—gets changed to the other (flipped!). Computer Scientists invented this technique so computers could discover where the error took place. If the learner is still interested, explain how the trick worked. 

How does the trick work??!!??


When the assistant adds the extra row and column, he is actually adding parity bits. For non-CS people, that means that the assistant adds another card to each row and column so the sum of face up cards in that row or column is now even. If there are an even number of face up cards in the row or column, the assistant adds a face down. If there are an odd number of face down cards in the row or column, he adds a face up.

The cards need to be put down seemingly without thought, like the assistant is just adding the extra row and column randomly. Here's a walkthrough:

Add a parity bit to the end of each of the columns

Add a parity bit to all of the rows, including the row you just added. (Notice that the column you are adding has parity automatically.)

Now when the learner flips a card, the row and column of the card that was flipped have an odd number of face up cards! You can quickly find the flipped card, even though you've never seen the grid before.


It works just as well when the flipped card is in the parity row or column.

The kids at the CSUnplugged show figured it out on their own, I was very impressed. The presenters used this trick as their opening act, and then explained it at the very end, so the kids had some time to think about it. If you want to see their explanation, check out this video:

Popular posts from this blog

Inspired

Colored Bits

The importance of mindset